blob: 45b327b0217e1bdc5ea6cec144ca9440899abcaf [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
khenaidoo106c61a2021-08-11 18:05:46 -040026 ic "github.com/opencord/voltha-protos/v5/go/inter_container"
27
28 "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
29 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053030 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
khenaidoo106c61a2021-08-11 18:05:46 -040031 "github.com/opencord/voltha-protos/v5/go/common"
32 oop "github.com/opencord/voltha-protos/v5/go/openolt"
33 "github.com/opencord/voltha-protos/v5/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040034)
35
36const (
Devmalya Paul41a762d2020-03-01 18:56:54 -050037 onuDiscoveryEvent = "ONU_DISCOVERY"
38 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
39 onuLobEvent = "ONU_LOSS_OF_BURST"
40 onuLopcMissEvent = "ONU_LOPC_MISS"
41 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
42 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
Gamze Abaka07868a52020-12-17 14:19:28 +000043 oltCommFailure = "OLT_COMMUNICATION_FAILURE"
Devmalya Paul41a762d2020-03-01 18:56:54 -050044 oltIndicationDown = "OLT_DOWN_INDICATION"
45 onuDyingGaspEvent = "ONU_DYING_GASP"
46 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
47 onuStartupFailEvent = "ONU_STARTUP_FAIL"
48 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
49 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
50 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
Devmalya Paul41a762d2020-03-01 18:56:54 -050051 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
52 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
53 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
54 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
55 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
56 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
57 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
58 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
59 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
60 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Pauleb5294e2020-03-19 03:01:39 -040061 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
Devmalya Paulfb990a52019-07-09 10:01:49 -040062)
63
64const (
Naga Manjunath9546b912019-11-28 20:56:20 +053065 // statusCheckOn represents status check On
66 statusCheckOn = "on"
67 // statusCheckOff represents status check Off
68 statusCheckOff = "off"
69 // operationStateUp represents operation state Up
70 operationStateUp = "up"
71 // operationStateDown represents operation state Down
72 operationStateDown = "down"
73 // base10 represents base 10 conversion
74 base10 = 10
75)
76
Amit Ghosh502056b2020-07-15 09:15:48 +010077const (
Gamze Abaka07868a52020-12-17 14:19:28 +000078 // ContextOltAdminState is for the admin state of the Olt in the context of the event
79 ContextOltAdminState = "admin-state"
80 // ContextOltConnectState is for the connect state of the Olt in the context of the event
81 ContextOltConnectState = "connect-state"
Amit Ghosh502056b2020-07-15 09:15:48 +010082 // ContextOltOperState is for the operational state of the Olt in the context of the event
83 ContextOltOperState = "oper-state"
Gamze Abaka07868a52020-12-17 14:19:28 +000084 // ContextOltVendor is for the Olt vendor in the context of the event
85 ContextOltVendor = "vendor"
86 // ContextOltType is for the Olt type in the context of the event
87 ContextOltType = "type"
88 // ContextOltParentID is for the Olt parent id in the context of the event
89 ContextOltParentID = "parent-id"
90 // ContextOltParentPortNo is for the Olt parent port no in the context of the event
91 ContextOltParentPortNo = "parent-port-no"
92 // ContextOltFirmwareVersion is for the Olt firmware version in the context of the event
93 ContextOltFirmwareVersion = "firmware-version"
94 // ContextOltHardwareVersion is for the Olt hardware version in the context of the event
95 ContextOltHardwareVersion = "hardware-version"
96 // ContextOltSerialNumber is for the serial number of the OLT
97 ContextOltSerialNumber = "serial-number"
98 // ContextOltMacAddress is for the OLT mac address
99 ContextOltMacAddress = "mac-address"
100 // ContextDeviceID is for the device id in the context of the event
101 ContextDeviceID = "id"
Amit Ghosh502056b2020-07-15 09:15:48 +0100102 // ContextOnuOnuID is for the Onu Id in the context of the event
103 ContextOnuOnuID = "onu-id"
104 // ContextOnuPonIntfID is for the PON interface Id on which the Onu Event occurred
105 ContextOnuPonIntfID = "intf-id"
106 // ContextOnuSerialNumber is for the serial number of the ONU
107 ContextOnuSerialNumber = "serial-number"
108 // ContextOnuDeviceID is for the device id of the ONU generated by VOLTHA
109 ContextOnuDeviceID = "onu-device-id"
110 // ContextOltPonIntfID is for the PON interface Id on an OLT event
111 ContextOltPonIntfID = "intf-id"
112 // ContextOnuFailureReaseon is for the reason of failure of/at ONU indicated by the event
113 ContextOnuFailureReaseon = "fail-reason"
114 // ContextOnuDrift is for the drift of an ONU in the context of an event
115 ContextOnuDrift = "drift"
116 // ContextOnuNewEqd is for the New Eqd of an ONU in the context of an event
117 ContextOnuNewEqd = "new-eqd"
118 // ContextOnuInverseBitErrorRate is for the inverse bit error rate in the context of an ONU event
119 ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
120 // ContextOltPonIntfOperState is for the operational state of a PON port in the context of an OLT event
121 ContextOltPonIntfOperState = "oper-state"
122 // ContextOnuRemoteDefectIndicatorCount is for the rdi in the context of an ONU event
123 ContextOnuRemoteDefectIndicatorCount = "rdi-count"
124 // ContextOnuDelineationErrors is for the delineation errors if present in an ONU events context
125 ContextOnuDelineationErrors = "delineation-errors"
126 // ContextOnuDifferentialDistance is for the differential distance in an ONU event context
127 ContextOnuDifferentialDistance = "differential-distance"
ssiddiqui04386ee2021-08-23 21:58:25 +0530128 // ContextOltPonTechnology is to indicate the pon-technology type, ie, 'GPON' or 'XGS-PON' (TODO check for combo?)
129 ContextOltPonTechnology = "pon-technology"
130 // ContextOltPortLabel is to indicate the string label of the pon-port, example: pon-0
131 ContextOltPortLabel = "port-label"
Amit Ghosh502056b2020-07-15 09:15:48 +0100132)
133
Devmalya Paulfb990a52019-07-09 10:01:49 -0400134// OpenOltEventMgr struct contains
135type OpenOltEventMgr struct {
Himani Chawlacd407802020-12-10 12:08:59 +0530136 eventProxy eventif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400137 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400138}
139
140// 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 +0530141func NewEventMgr(eventProxy eventif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400142 var em OpenOltEventMgr
143 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400144 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400145 return &em
146}
147
148// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500149// nolint: gocyclo
Kent Hagermane6ff1012020-07-14 15:07:53 -0400150func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +0530151 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400152 switch alarmInd.Data.(type) {
153 case *oop.AlarmIndication_LosInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000154 logger.Debugw(ctx, "received-los-indication", log.Fields{"alarm-ind": alarmInd})
155 err = em.oltLosIndication(ctx, alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400156 case *oop.AlarmIndication_OnuAlarmInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000157 logger.Debugw(ctx, "received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
158 err = em.onuAlarmIndication(ctx, alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400159 case *oop.AlarmIndication_DyingGaspInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000160 logger.Debugw(ctx, "received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
161 err = em.onuDyingGaspIndication(ctx, alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400162 case *oop.AlarmIndication_OnuLossOmciInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000163 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
164 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400165 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000166 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
167 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400168 case *oop.AlarmIndication_OnuSignalDegradeInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000169 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
170 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400171 case *oop.AlarmIndication_OnuSignalsFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000172 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
173 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530174 case *oop.AlarmIndication_OnuStartupFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000175 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
176 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400177 case *oop.AlarmIndication_OnuTiwiInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000178 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
179 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530180 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000181 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
182 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
Naga Manjunath9546b912019-11-28 20:56:20 +0530183 case *oop.AlarmIndication_OnuItuPonStatsInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000184 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
185 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500186 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000187 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
188 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500189 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000190 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
191 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500192 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000193 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
194 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500195 case *oop.AlarmIndication_OnuLossOfAckInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000196 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
197 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400198 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000199 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
200 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400201 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530202 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400203 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530204 if err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400205 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
Naga Manjunath9546b912019-11-28 20:56:20 +0530206 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400207}
208
Gamze Abaka07868a52020-12-17 14:19:28 +0000209func (em *OpenOltEventMgr) oltCommunicationEvent(ctx context.Context, device *voltha.Device, raisedTs int64) {
210 if device == nil {
211 logger.Warn(ctx, "device-is-nil-can't-send-olt-communication-failure-event")
212 return
213 }
214 var de voltha.DeviceEvent
215 context := make(map[string]string)
216 context[ContextOltOperState] = device.OperStatus.String()
217 context[ContextOltAdminState] = device.AdminState.String()
218 context[ContextOltVendor] = device.Vendor
219 context[ContextOltConnectState] = device.ConnectStatus.String()
220 context[ContextOltType] = device.Type
221 context[ContextOltParentID] = device.ParentId
222 context[ContextOltParentPortNo] = fmt.Sprintf("%d", device.ParentPortNo)
223 context[ContextDeviceID] = device.Id
224 context[ContextOltFirmwareVersion] = device.FirmwareVersion
225 context[ContextOltHardwareVersion] = device.HardwareVersion
226 context[ContextOltSerialNumber] = device.SerialNumber
227 context[ContextOltMacAddress] = device.MacAddress
228 de.Context = context
229 de.ResourceId = device.Id
230
231 if device.ConnectStatus == voltha.ConnectStatus_UNREACHABLE {
232 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "RAISE_EVENT")
233 } else {
234 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "CLEAR_EVENT")
235 }
236
237 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
238 logger.Errorw(ctx, "failed-to-send-olt-comm-failure-event", log.Fields{"err": err})
239 }
240 logger.Debugw(ctx, "olt-comm-failure-event-sent-to-kafka",
241 log.Fields{
242 "device-id": device.Id,
243 "connect-status": device.ConnectStatus,
244 })
245}
246
Daniele Rossi051466a2019-07-26 13:39:37 +0000247// oltUpDownIndication handles Up and Down state of an OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000248func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000249 var de voltha.DeviceEvent
250 context := make(map[string]string)
251 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100252 context[ContextOltOperState] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000253 /* Populating device event body */
254 de.Context = context
255 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530256 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000257 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530258 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000259 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
260 }
261 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400262 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000263 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000264 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000265 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530266 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000267}
268
Devmalya Paulfb990a52019-07-09 10:01:49 -0400269// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Neha Sharma96b7bf22020-06-15 10:37:32 +0000270func (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 -0400271 var de voltha.DeviceEvent
272 context := make(map[string]string)
273 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100274 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
275 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
276 context[ContextOnuSerialNumber] = serialNumber
277 context[ContextOnuDeviceID] = onuDeviceID
ssiddiqui04386ee2021-08-23 21:58:25 +0530278 context[ContextOltPonTechnology] = em.handler.getPonTechnology(onuDisc.IntfId)
279 context[ContextOltPortLabel], _ = GetportLabel(onuDisc.GetIntfId(), voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400280 /* Populating device event body */
281 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100282 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400283 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
284 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400285 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530286 return olterrors.NewErrCommunication("send-onu-discovery-event",
287 log.Fields{
288 "serial-number": serialNumber,
289 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400290 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000291 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
Shrey Baid26912972020-04-16 21:02:31 +0530292 log.Fields{
293 "serial-number": serialNumber,
294 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530295 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400296}
297
Neha Sharma96b7bf22020-06-15 10:37:32 +0000298func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530299 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400300 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530301 var alarmInd oop.OnuAlarmIndication
302 ponIntdID := PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
303
Devmalya Paulfb990a52019-07-09 10:01:49 -0400304 context := make(map[string]string)
305 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100306 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400307 /* Populating device event body */
308 de.Context = context
309 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530310 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400311 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530312
313 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
314 with "los_status: on" should be raised for each Onu connected to the PON
315 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
316 for all the ONU's connected to PON on receiving LoSIndication for PON */
317 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
318 if onuInCache.(*OnuDevice).intfID == ponIntdID {
319 alarmInd.IntfId = ponIntdID
320 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
321 alarmInd.LosStatus = statusCheckOn
Neha Sharma96b7bf22020-06-15 10:37:32 +0000322 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530323 }
324 return true
325 })
326 if err != nil {
327 /* Return if any error encountered while processing ONU LoS Event*/
328 return err
329 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400330 } else {
331 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
332 }
333 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100334 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530335 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400336 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000337 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530338 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400339}
340
Amit Ghosh502056b2020-07-15 09:15:48 +0100341func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) {
342 var serialNumber = ""
343 var onuDeviceID = ""
344 onu := em.handler.formOnuKey(intfID, onuID)
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530345 if onu, ok := em.handler.onus.Load(onu); ok {
346 serialNumber = onu.(*OnuDevice).serialNumber
Amit Ghosh502056b2020-07-15 09:15:48 +0100347 onuDeviceID = onu.(*OnuDevice).deviceID
Devmalya Paul90ca3012019-09-02 21:55:45 -0400348 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100349
ssiddiqui04386ee2021-08-23 21:58:25 +0530350 context[ContextOltPortLabel], _ = GetportLabel(intfID, voltha.Port_PON_OLT)
Amit Ghosh502056b2020-07-15 09:15:48 +0100351 context[ContextOnuSerialNumber] = serialNumber
352 context[ContextOnuDeviceID] = onuDeviceID
353}
354
355func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
356 var de voltha.DeviceEvent
357 context := make(map[string]string)
358 /* Populating event context */
359 em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
360
361 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
362 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
363
Devmalya Paulfb990a52019-07-09 10:01:49 -0400364 /* Populating device event body */
365 de.Context = context
366 de.ResourceId = deviceID
Thomas Lee Sf68399e2020-02-11 15:41:38 +0530367 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400368 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100369 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530370 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400371 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000372 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530373 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400374}
375
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530376//wasLosRaised checks whether los raised already. If already raised returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000377func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530378 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
379 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000380 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530381
382 if onuAlarm.LosStatus == statusCheckOn {
383 if onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000384 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530385 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
386 return true
387 }
388 return false
389 }
390 }
391 return true
392}
393
394//wasLosCleared checks whether los cleared already. If already cleared returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000395func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530396 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
397 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000398 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530399
400 if onuAlarm.LosStatus == statusCheckOff {
401 if !onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000402 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530403 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
404 return true
405 }
406 return false
407 }
408 }
409 return true
410}
411
412func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
413 var deviceEventName string
414 if onuAlarm.LosStatus == statusCheckOn {
415 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
416 } else if onuAlarm.LosStatus == statusCheckOff {
417 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
418 } else if onuAlarm.LobStatus == statusCheckOn {
419 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
420 } else if onuAlarm.LobStatus == statusCheckOff {
421 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
422 } else if onuAlarm.LopcMissStatus == statusCheckOn {
423 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
424 } else if onuAlarm.LopcMissStatus == statusCheckOff {
425 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
426 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
427 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
428 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
429 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
430 } else if onuAlarm.LofiStatus == statusCheckOn {
431 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
432 } else if onuAlarm.LofiStatus == statusCheckOff {
433 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
434 } else if onuAlarm.LoamiStatus == statusCheckOn {
435 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
436 } else if onuAlarm.LoamiStatus == statusCheckOff {
437 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
438 }
439 return deviceEventName
440}
441
Neha Sharma96b7bf22020-06-15 10:37:32 +0000442func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400443 var de voltha.DeviceEvent
Amit Ghosh502056b2020-07-15 09:15:48 +0100444
Devmalya Paulfb990a52019-07-09 10:01:49 -0400445 context := make(map[string]string)
446 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100447 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
448 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
449 em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530450
Devmalya Paulfb990a52019-07-09 10:01:49 -0400451 /* Populating device event body */
452 de.Context = context
453 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530454 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
455
456 switch onuAlarm.LosStatus {
457 case statusCheckOn:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000458 if em.wasLosRaised(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530459 /* No need to raise Onu Los Event as it might have already raised
460 or Onu might have deleted */
461 return nil
462 }
463 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
464 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
465 /* Update onu device with LoS raised state as true */
466 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
467 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400468 onuInCache.(*OnuDevice).proxyDeviceID, true, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530469 }
470 case statusCheckOff:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000471 if em.wasLosCleared(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530472 /* No need to clear Onu Los Event as it might have already cleared
473 or Onu might have deleted */
474 return nil
475 }
476 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
477 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
478 /* Update onu device with LoS raised state as false */
479 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
480 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400481 onuInCache.(*OnuDevice).proxyDeviceID, false, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530482 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400483 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530484
Devmalya Paulfb990a52019-07-09 10:01:49 -0400485 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400486 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530487 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400488 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000489 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 +0530490 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400491}
492
kesavand7cf3a052020-08-28 12:49:18 +0530493func (em *OpenOltEventMgr) onuActivationIndication(ctx context.Context, eventName string, onuInd *oop.OnuIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400494 var de voltha.DeviceEvent
495 context := make(map[string]string)
496 /* Populating event context */
kesavand7cf3a052020-08-28 12:49:18 +0530497 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuInd.IntfId), base10)
498 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuInd.OnuId), base10)
499 context[ContextOnuFailureReaseon] = onuInd.FailReason.String()
Amit Ghosh502056b2020-07-15 09:15:48 +0100500
kesavand7cf3a052020-08-28 12:49:18 +0530501 em.populateContextWithSerialDeviceID(context, onuInd.IntfId, onuInd.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100502
Devmalya Paulfb990a52019-07-09 10:01:49 -0400503 /* Populating device event body */
504 de.Context = context
505 de.ResourceId = deviceID
kesavand7cf3a052020-08-28 12:49:18 +0530506 de.DeviceEventName = eventName
Devmalya Paulfb990a52019-07-09 10:01:49 -0400507 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400508 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530509 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400510 }
kesavand7cf3a052020-08-28 12:49:18 +0530511 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 +0530512 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400513}
514
Neha Sharma96b7bf22020-06-15 10:37:32 +0000515func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400516 var de voltha.DeviceEvent
517 context := make(map[string]string)
518 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100519 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
520 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
521
522 em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
523
Devmalya Paulfb990a52019-07-09 10:01:49 -0400524 /* Populating device event body */
525 de.Context = context
526 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530527 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400528 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
529 } else {
530 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
531 }
532 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100533 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530534 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400535 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000536 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 +0530537 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400538}
539
Neha Sharma96b7bf22020-06-15 10:37:32 +0000540func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400541 var de voltha.DeviceEvent
542 context := make(map[string]string)
543 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100544 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
545 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
546 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
547 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
548
549 em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
550
Devmalya Paulfb990a52019-07-09 10:01:49 -0400551 /* Populating device event body */
552 de.Context = context
553 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530554 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400555 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
556 } else {
557 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
558 }
559 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100560 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530561 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400562 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000563 logger.Debugw(ctx, "onu-drift-of-window-event-sent-to-kafka", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530564 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400565}
566
Neha Sharma96b7bf22020-06-15 10:37:32 +0000567func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400568 var de voltha.DeviceEvent
569 context := make(map[string]string)
570 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100571 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
572 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
573 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
574
575 em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
576
Devmalya Paulfb990a52019-07-09 10:01:49 -0400577 /* Populating device event body */
578 de.Context = context
579 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530580 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400581 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
582 } else {
583 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
584 }
585 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100586 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530587 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400588 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000589 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 +0530590 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400591}
592
Neha Sharma96b7bf22020-06-15 10:37:32 +0000593func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400594 var de voltha.DeviceEvent
595 context := make(map[string]string)
596 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100597 em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
598
599 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
600 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
601 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400602 /* Populating device event body */
603 de.Context = context
604 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530605 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400606 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
607 } else {
608 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
609 }
610 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100611 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530612 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400613 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000614 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 +0530615 return nil
616}
617
Neha Sharma96b7bf22020-06-15 10:37:32 +0000618func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530619 var de voltha.DeviceEvent
620 context := make(map[string]string)
621 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100622 em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
623
624 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
625 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530626
627 /* Populating device event body */
628 de.Context = context
629 de.ResourceId = deviceID
630 if onuStartupFail.Status == statusCheckOn {
631 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
632 } else {
633 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
634 }
635 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400636 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530637 return err
638 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000639 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 +0530640 return nil
641}
642
Neha Sharma96b7bf22020-06-15 10:37:32 +0000643func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530644 var de voltha.DeviceEvent
645 context := make(map[string]string)
646 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100647 em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
648
649 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
650 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
Naga Manjunath9546b912019-11-28 20:56:20 +0530651 /* Populating device event body */
652 de.Context = context
653 de.ResourceId = deviceID
654 if onuLOKI.Status == statusCheckOn {
655 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
656 } else {
657 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
658 }
659
660 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400661 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530662 return err
663 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000664 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 +0530665 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400666}
kesavand39e0aa32020-01-28 20:58:50 -0500667
668// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Kent Hagermane6ff1012020-07-14 15:07:53 -0400669func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400670 portNo := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
khenaidoo106c61a2021-08-11 18:05:46 -0400671 if port, err := em.handler.getPortFromCore(ctx, &ic.PortFilter{
672 DeviceId: deviceID,
673 Port: portNo,
674 }); err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700675 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "err": err})
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400676 } else if port.AdminState != common.AdminState_ENABLED {
677 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 -0400678 return
kesavand39e0aa32020-01-28 20:58:50 -0500679 }
680 /* Populating event context */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400681 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
kesavand39e0aa32020-01-28 20:58:50 -0500682 /* Populating device event body */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400683 var de voltha.DeviceEvent
kesavand39e0aa32020-01-28 20:58:50 -0500684 de.Context = context
685 de.ResourceId = deviceID
686
687 if ifindication.GetOperState() == operationStateDown {
688 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
689 } else if ifindication.OperState == operationStateUp {
690 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
691 }
692 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400693 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
694 _ = 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)
695 return
kesavand39e0aa32020-01-28 20:58:50 -0500696 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000697 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
kesavand39e0aa32020-01-28 20:58:50 -0500698}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500699
Neha Sharma96b7bf22020-06-15 10:37:32 +0000700func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500701 var de voltha.DeviceEvent
702 context := make(map[string]string)
703 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100704 em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
705
706 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
707 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500708 /* Populating device event body */
709 de.Context = context
710 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400711 if onuDFI.Status == statusCheckOn {
712 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
713 } else {
714 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
715 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500716 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400717 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500718 return err
719 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000720 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 -0500721 return nil
722}
Amit Ghosh502056b2020-07-15 09:15:48 +0100723
Neha Sharma96b7bf22020-06-15 10:37:32 +0000724func (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 -0500725 /* Populating event context */
726 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100727 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
728 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
729 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500730 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100731 em.populateContextWithSerialDeviceID(context, intfID, onuID)
732
Devmalya Paul6f063a62020-02-19 19:19:06 -0500733 /* Populating device event body */
734 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400735 Context: context,
736 ResourceId: deviceID,
737 }
738 if status == statusCheckOn {
739 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
740 } else {
741 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500742 }
743 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400744 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500745 return err
746 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000747 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 -0400748 return nil
749}
750
Neha Sharma96b7bf22020-06-15 10:37:32 +0000751func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
Devmalya Paula1efa642020-04-20 01:36:43 -0400752 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
753 if !found {
754 return errors.New("unknown-onu-device")
755 }
756 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
757 if !onuDevice.(*OnuDevice).rdiRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000758 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400759 return err
760 }
761 onuDevice.(*OnuDevice).rdiRaised = true
762 return nil
763 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000764 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 -0400765 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000766 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400767 return err
768 }
769 onuDevice.(*OnuDevice).rdiRaised = false
770 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500771 return nil
772}
773
Neha Sharma96b7bf22020-06-15 10:37:32 +0000774func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500775 /* Populating event context */
776 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100777 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
778 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
779 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500780 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100781 em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
782
Devmalya Paul41a762d2020-03-01 18:56:54 -0500783 /* Populating device event body */
784 de := &voltha.DeviceEvent{
785 Context: context,
786 ResourceId: deviceID,
787 }
788 if onuGCD.Status == statusCheckOn {
789 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
790 } else {
791 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
792 }
793 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400794 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500795 return err
796 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000797 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 -0500798 return nil
799}
800
Neha Sharma96b7bf22020-06-15 10:37:32 +0000801func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500802 /* Populating event context */
803 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100804 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
805 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500806 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100807 em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500808 /* Populating device event body */
809 de := &voltha.DeviceEvent{
810 Context: context,
811 ResourceId: deviceID,
812 }
813 if onuErr.Status == statusCheckOn {
814 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
815 } else {
816 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
817 }
818 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400819 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500820 return err
821 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000822 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 -0500823 return nil
824}
825
Neha Sharma96b7bf22020-06-15 10:37:32 +0000826func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500827 /* Populating event context */
828 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100829 ContextOnuOnuID: strconv.FormatUint(uint64(onuLOA.OnuId), base10),
830 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500831 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100832 em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
833
Devmalya Paul41a762d2020-03-01 18:56:54 -0500834 /* Populating device event body */
835 de := &voltha.DeviceEvent{
836 Context: context,
837 ResourceId: deviceID,
838 }
839 if onuLOA.Status == statusCheckOn {
840 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
841 } else {
842 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
843 }
844 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400845 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500846 return err
847 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000848 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 -0500849 return nil
850}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400851
Neha Sharma96b7bf22020-06-15 10:37:32 +0000852func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400853 /* Populating event context */
854 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100855 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
856 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
857 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400858 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100859 em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
860
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400861 /* Populating device event body */
862 de := &voltha.DeviceEvent{
863 Context: context,
864 ResourceId: deviceID,
865 }
866 if onuDRE.Status == statusCheckOn {
867 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
868 } else {
869 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
870 }
871 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400872 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400873 return err
874 }
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000875 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 -0400876 return nil
877}