blob: 971a173223e73b58b49359a89c070720298815e1 [file] [log] [blame]
Devmalya Paulfb990a52019-07-09 10:01:49 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Scott Bakerdbd960e2020-02-28 08:57:51 -080017// Package core provides APIs for the openOLT adapter
18package core
Devmalya Paulfb990a52019-07-09 10:01:49 -040019
20import (
Neha Sharma96b7bf22020-06-15 10:37:32 +000021 "context"
Devmalya Paula1efa642020-04-20 01:36:43 -040022 "errors"
Devmalya Paulfb990a52019-07-09 10:01:49 -040023 "fmt"
Naga Manjunath9546b912019-11-28 20:56:20 +053024 "strconv"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053025
khenaidoodc2116e2021-10-19 17:33:19 -040026 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo106c61a2021-08-11 18:05:46 -040027
28 "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
29 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Mahir Gunyel85f61c12021-10-06 11:53:45 -070030 plt "github.com/opencord/voltha-lib-go/v7/pkg/platform"
Thomas Lee S94109f12020-03-03 16:39:29 +053031 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
khenaidoo106c61a2021-08-11 18:05:46 -040032 "github.com/opencord/voltha-protos/v5/go/common"
33 oop "github.com/opencord/voltha-protos/v5/go/openolt"
34 "github.com/opencord/voltha-protos/v5/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040035)
36
37const (
Devmalya Paul41a762d2020-03-01 18:56:54 -050038 onuDiscoveryEvent = "ONU_DISCOVERY"
39 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
40 onuLobEvent = "ONU_LOSS_OF_BURST"
41 onuLopcMissEvent = "ONU_LOPC_MISS"
42 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
43 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
Gamze Abaka07868a52020-12-17 14:19:28 +000044 oltCommFailure = "OLT_COMMUNICATION_FAILURE"
Devmalya Paul41a762d2020-03-01 18:56:54 -050045 oltIndicationDown = "OLT_DOWN_INDICATION"
46 onuDyingGaspEvent = "ONU_DYING_GASP"
47 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
48 onuStartupFailEvent = "ONU_STARTUP_FAIL"
49 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
50 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
51 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
Devmalya Paul41a762d2020-03-01 18:56:54 -050052 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
53 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
54 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
55 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
56 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
57 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
58 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
59 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
60 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
61 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Pauleb5294e2020-03-19 03:01:39 -040062 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
Devmalya Paulfb990a52019-07-09 10:01:49 -040063)
64
65const (
Naga Manjunath9546b912019-11-28 20:56:20 +053066 // statusCheckOn represents status check On
67 statusCheckOn = "on"
68 // statusCheckOff represents status check Off
69 statusCheckOff = "off"
70 // operationStateUp represents operation state Up
71 operationStateUp = "up"
72 // operationStateDown represents operation state Down
73 operationStateDown = "down"
74 // base10 represents base 10 conversion
75 base10 = 10
76)
77
Amit Ghosh502056b2020-07-15 09:15:48 +010078const (
Gamze Abaka07868a52020-12-17 14:19:28 +000079 // ContextOltAdminState is for the admin state of the Olt in the context of the event
80 ContextOltAdminState = "admin-state"
81 // ContextOltConnectState is for the connect state of the Olt in the context of the event
82 ContextOltConnectState = "connect-state"
Amit Ghosh502056b2020-07-15 09:15:48 +010083 // ContextOltOperState is for the operational state of the Olt in the context of the event
84 ContextOltOperState = "oper-state"
Gamze Abaka07868a52020-12-17 14:19:28 +000085 // ContextOltVendor is for the Olt vendor in the context of the event
86 ContextOltVendor = "vendor"
87 // ContextOltType is for the Olt type in the context of the event
88 ContextOltType = "type"
89 // ContextOltParentID is for the Olt parent id in the context of the event
90 ContextOltParentID = "parent-id"
91 // ContextOltParentPortNo is for the Olt parent port no in the context of the event
92 ContextOltParentPortNo = "parent-port-no"
93 // ContextOltFirmwareVersion is for the Olt firmware version in the context of the event
94 ContextOltFirmwareVersion = "firmware-version"
95 // ContextOltHardwareVersion is for the Olt hardware version in the context of the event
96 ContextOltHardwareVersion = "hardware-version"
97 // ContextOltSerialNumber is for the serial number of the OLT
98 ContextOltSerialNumber = "serial-number"
99 // ContextOltMacAddress is for the OLT mac address
100 ContextOltMacAddress = "mac-address"
101 // ContextDeviceID is for the device id in the context of the event
102 ContextDeviceID = "id"
Amit Ghosh502056b2020-07-15 09:15:48 +0100103 // ContextOnuOnuID is for the Onu Id in the context of the event
104 ContextOnuOnuID = "onu-id"
105 // ContextOnuPonIntfID is for the PON interface Id on which the Onu Event occurred
106 ContextOnuPonIntfID = "intf-id"
107 // ContextOnuSerialNumber is for the serial number of the ONU
108 ContextOnuSerialNumber = "serial-number"
109 // ContextOnuDeviceID is for the device id of the ONU generated by VOLTHA
110 ContextOnuDeviceID = "onu-device-id"
111 // ContextOltPonIntfID is for the PON interface Id on an OLT event
112 ContextOltPonIntfID = "intf-id"
113 // ContextOnuFailureReaseon is for the reason of failure of/at ONU indicated by the event
114 ContextOnuFailureReaseon = "fail-reason"
115 // ContextOnuDrift is for the drift of an ONU in the context of an event
116 ContextOnuDrift = "drift"
117 // ContextOnuNewEqd is for the New Eqd of an ONU in the context of an event
118 ContextOnuNewEqd = "new-eqd"
119 // ContextOnuInverseBitErrorRate is for the inverse bit error rate in the context of an ONU event
120 ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
121 // ContextOltPonIntfOperState is for the operational state of a PON port in the context of an OLT event
122 ContextOltPonIntfOperState = "oper-state"
123 // ContextOnuRemoteDefectIndicatorCount is for the rdi in the context of an ONU event
124 ContextOnuRemoteDefectIndicatorCount = "rdi-count"
125 // ContextOnuDelineationErrors is for the delineation errors if present in an ONU events context
126 ContextOnuDelineationErrors = "delineation-errors"
127 // ContextOnuDifferentialDistance is for the differential distance in an ONU event context
128 ContextOnuDifferentialDistance = "differential-distance"
ssiddiqui04386ee2021-08-23 21:58:25 +0530129 // ContextOltPonTechnology is to indicate the pon-technology type, ie, 'GPON' or 'XGS-PON' (TODO check for combo?)
130 ContextOltPonTechnology = "pon-technology"
131 // ContextOltPortLabel is to indicate the string label of the pon-port, example: pon-0
132 ContextOltPortLabel = "port-label"
Amit Ghosh502056b2020-07-15 09:15:48 +0100133)
134
Devmalya Paulfb990a52019-07-09 10:01:49 -0400135// OpenOltEventMgr struct contains
136type OpenOltEventMgr struct {
Himani Chawlacd407802020-12-10 12:08:59 +0530137 eventProxy eventif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400138 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400139}
140
141// NewEventMgr is a Function to get a new event manager struct for the OpenOLT to process and publish OpenOLT event
Himani Chawlacd407802020-12-10 12:08:59 +0530142func NewEventMgr(eventProxy eventif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400143 var em OpenOltEventMgr
144 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400145 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400146 return &em
147}
148
149// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500150// nolint: gocyclo
Kent Hagermane6ff1012020-07-14 15:07:53 -0400151func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +0530152 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400153 switch alarmInd.Data.(type) {
154 case *oop.AlarmIndication_LosInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000155 logger.Debugw(ctx, "received-los-indication", log.Fields{"alarm-ind": alarmInd})
156 err = em.oltLosIndication(ctx, alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400157 case *oop.AlarmIndication_OnuAlarmInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000158 logger.Debugw(ctx, "received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
159 err = em.onuAlarmIndication(ctx, alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400160 case *oop.AlarmIndication_DyingGaspInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000161 logger.Debugw(ctx, "received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
162 err = em.onuDyingGaspIndication(ctx, alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400163 case *oop.AlarmIndication_OnuLossOmciInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000164 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
165 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400166 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000167 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
168 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400169 case *oop.AlarmIndication_OnuSignalDegradeInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000170 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
171 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400172 case *oop.AlarmIndication_OnuSignalsFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000173 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
174 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530175 case *oop.AlarmIndication_OnuStartupFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000176 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
177 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400178 case *oop.AlarmIndication_OnuTiwiInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000179 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
180 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530181 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000182 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
183 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
Naga Manjunath9546b912019-11-28 20:56:20 +0530184 case *oop.AlarmIndication_OnuItuPonStatsInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000185 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
186 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500187 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000188 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
189 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500190 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000191 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
192 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500193 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000194 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
195 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500196 case *oop.AlarmIndication_OnuLossOfAckInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000197 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
198 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400199 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000200 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
201 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400202 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530203 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400204 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530205 if err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400206 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
Naga Manjunath9546b912019-11-28 20:56:20 +0530207 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400208}
209
Gamze Abaka07868a52020-12-17 14:19:28 +0000210func (em *OpenOltEventMgr) oltCommunicationEvent(ctx context.Context, device *voltha.Device, raisedTs int64) {
211 if device == nil {
212 logger.Warn(ctx, "device-is-nil-can't-send-olt-communication-failure-event")
213 return
214 }
215 var de voltha.DeviceEvent
216 context := make(map[string]string)
217 context[ContextOltOperState] = device.OperStatus.String()
218 context[ContextOltAdminState] = device.AdminState.String()
219 context[ContextOltVendor] = device.Vendor
220 context[ContextOltConnectState] = device.ConnectStatus.String()
221 context[ContextOltType] = device.Type
222 context[ContextOltParentID] = device.ParentId
223 context[ContextOltParentPortNo] = fmt.Sprintf("%d", device.ParentPortNo)
224 context[ContextDeviceID] = device.Id
225 context[ContextOltFirmwareVersion] = device.FirmwareVersion
226 context[ContextOltHardwareVersion] = device.HardwareVersion
227 context[ContextOltSerialNumber] = device.SerialNumber
228 context[ContextOltMacAddress] = device.MacAddress
229 de.Context = context
230 de.ResourceId = device.Id
231
232 if device.ConnectStatus == voltha.ConnectStatus_UNREACHABLE {
233 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "RAISE_EVENT")
234 } else {
235 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "CLEAR_EVENT")
236 }
237
238 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
239 logger.Errorw(ctx, "failed-to-send-olt-comm-failure-event", log.Fields{"err": err})
240 }
241 logger.Debugw(ctx, "olt-comm-failure-event-sent-to-kafka",
242 log.Fields{
243 "device-id": device.Id,
244 "connect-status": device.ConnectStatus,
245 })
246}
247
Daniele Rossi051466a2019-07-26 13:39:37 +0000248// oltUpDownIndication handles Up and Down state of an OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000249func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000250 var de voltha.DeviceEvent
251 context := make(map[string]string)
252 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100253 context[ContextOltOperState] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000254 /* Populating device event body */
255 de.Context = context
256 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530257 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000258 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530259 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000260 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
261 }
262 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400263 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000264 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000265 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000266 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530267 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000268}
269
Devmalya Paulfb990a52019-07-09 10:01:49 -0400270// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Neha Sharma96b7bf22020-06-15 10:37:32 +0000271func (em *OpenOltEventMgr) OnuDiscoveryIndication(ctx context.Context, onuDisc *oop.OnuDiscIndication, oltDeviceID string, onuDeviceID string, OnuID uint32, serialNumber string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400272 var de voltha.DeviceEvent
273 context := make(map[string]string)
274 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100275 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
276 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
277 context[ContextOnuSerialNumber] = serialNumber
278 context[ContextOnuDeviceID] = onuDeviceID
ssiddiqui04386ee2021-08-23 21:58:25 +0530279 context[ContextOltPonTechnology] = em.handler.getPonTechnology(onuDisc.IntfId)
280 context[ContextOltPortLabel], _ = GetportLabel(onuDisc.GetIntfId(), voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400281 /* Populating device event body */
282 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100283 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400284 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
285 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400286 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530287 return olterrors.NewErrCommunication("send-onu-discovery-event",
288 log.Fields{
289 "serial-number": serialNumber,
290 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400291 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000292 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
Shrey Baid26912972020-04-16 21:02:31 +0530293 log.Fields{
294 "serial-number": serialNumber,
295 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530296 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400297}
298
Neha Sharma96b7bf22020-06-15 10:37:32 +0000299func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530300 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400301 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530302 var alarmInd oop.OnuAlarmIndication
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700303 ponIntdID := plt.PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530304
Devmalya Paulfb990a52019-07-09 10:01:49 -0400305 context := make(map[string]string)
306 /* Populating event context */
yasin sapli0b242942021-10-11 08:51:16 +0000307 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(ponIntdID), base10)
Abhilash Laxmeshwar42b58242021-11-24 19:27:25 +0530308 context[ContextOltPortLabel], _ = GetportLabel(oltLos.IntfId, voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400309 /* Populating device event body */
310 de.Context = context
311 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530312 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400313 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530314
315 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
316 with "los_status: on" should be raised for each Onu connected to the PON
317 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
318 for all the ONU's connected to PON on receiving LoSIndication for PON */
319 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
320 if onuInCache.(*OnuDevice).intfID == ponIntdID {
321 alarmInd.IntfId = ponIntdID
322 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
323 alarmInd.LosStatus = statusCheckOn
Neha Sharma96b7bf22020-06-15 10:37:32 +0000324 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530325 }
326 return true
327 })
328 if err != nil {
329 /* Return if any error encountered while processing ONU LoS Event*/
330 return err
331 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400332 } else {
333 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
334 }
335 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100336 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530337 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400338 }
yasin sapli0b242942021-10-11 08:51:16 +0000339 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": ponIntdID})
Naga Manjunath9546b912019-11-28 20:56:20 +0530340 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400341}
342
Amit Ghosh502056b2020-07-15 09:15:48 +0100343func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) {
344 var serialNumber = ""
345 var onuDeviceID = ""
346 onu := em.handler.formOnuKey(intfID, onuID)
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530347 if onu, ok := em.handler.onus.Load(onu); ok {
348 serialNumber = onu.(*OnuDevice).serialNumber
Amit Ghosh502056b2020-07-15 09:15:48 +0100349 onuDeviceID = onu.(*OnuDevice).deviceID
Devmalya Paul90ca3012019-09-02 21:55:45 -0400350 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100351
ssiddiqui04386ee2021-08-23 21:58:25 +0530352 context[ContextOltPortLabel], _ = GetportLabel(intfID, voltha.Port_PON_OLT)
Amit Ghosh502056b2020-07-15 09:15:48 +0100353 context[ContextOnuSerialNumber] = serialNumber
354 context[ContextOnuDeviceID] = onuDeviceID
355}
356
357func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
358 var de voltha.DeviceEvent
359 context := make(map[string]string)
360 /* Populating event context */
361 em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
362
363 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
364 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
365
Devmalya Paulfb990a52019-07-09 10:01:49 -0400366 /* Populating device event body */
367 de.Context = context
368 de.ResourceId = deviceID
Thomas Lee Sf68399e2020-02-11 15:41:38 +0530369 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400370 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100371 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530372 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400373 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000374 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530375 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400376}
377
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530378//wasLosRaised checks whether los raised already. If already raised returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000379func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530380 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
381 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000382 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530383
384 if onuAlarm.LosStatus == statusCheckOn {
385 if onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000386 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530387 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
388 return true
389 }
390 return false
391 }
392 }
393 return true
394}
395
396//wasLosCleared checks whether los cleared already. If already cleared returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000397func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530398 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
399 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000400 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530401
402 if onuAlarm.LosStatus == statusCheckOff {
403 if !onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000404 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530405 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
406 return true
407 }
408 return false
409 }
410 }
411 return true
412}
413
414func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
415 var deviceEventName string
416 if onuAlarm.LosStatus == statusCheckOn {
417 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
418 } else if onuAlarm.LosStatus == statusCheckOff {
419 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
420 } else if onuAlarm.LobStatus == statusCheckOn {
421 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
422 } else if onuAlarm.LobStatus == statusCheckOff {
423 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
424 } else if onuAlarm.LopcMissStatus == statusCheckOn {
425 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
426 } else if onuAlarm.LopcMissStatus == statusCheckOff {
427 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
428 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
429 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
430 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
431 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
432 } else if onuAlarm.LofiStatus == statusCheckOn {
433 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
434 } else if onuAlarm.LofiStatus == statusCheckOff {
435 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
436 } else if onuAlarm.LoamiStatus == statusCheckOn {
437 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
438 } else if onuAlarm.LoamiStatus == statusCheckOff {
439 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
440 }
441 return deviceEventName
442}
443
Neha Sharma96b7bf22020-06-15 10:37:32 +0000444func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400445 var de voltha.DeviceEvent
Amit Ghosh502056b2020-07-15 09:15:48 +0100446
Devmalya Paulfb990a52019-07-09 10:01:49 -0400447 context := make(map[string]string)
448 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100449 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
450 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
451 em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530452
Devmalya Paulfb990a52019-07-09 10:01:49 -0400453 /* Populating device event body */
454 de.Context = context
455 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530456 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
457
458 switch onuAlarm.LosStatus {
459 case statusCheckOn:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000460 if em.wasLosRaised(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530461 /* No need to raise Onu Los Event as it might have already raised
462 or Onu might have deleted */
463 return nil
464 }
465 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
466 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
467 /* Update onu device with LoS raised state as true */
468 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
469 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400470 onuInCache.(*OnuDevice).proxyDeviceID, true, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530471 }
472 case statusCheckOff:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000473 if em.wasLosCleared(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530474 /* No need to clear Onu Los Event as it might have already cleared
475 or Onu might have deleted */
476 return nil
477 }
478 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
479 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
480 /* Update onu device with LoS raised state as false */
481 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
482 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400483 onuInCache.(*OnuDevice).proxyDeviceID, false, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530484 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400485 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530486
Devmalya Paulfb990a52019-07-09 10:01:49 -0400487 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400488 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530489 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400490 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000491 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 +0530492 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400493}
494
kesavand7cf3a052020-08-28 12:49:18 +0530495func (em *OpenOltEventMgr) onuActivationIndication(ctx context.Context, eventName string, onuInd *oop.OnuIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400496 var de voltha.DeviceEvent
497 context := make(map[string]string)
498 /* Populating event context */
kesavand7cf3a052020-08-28 12:49:18 +0530499 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuInd.IntfId), base10)
500 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuInd.OnuId), base10)
501 context[ContextOnuFailureReaseon] = onuInd.FailReason.String()
Amit Ghosh502056b2020-07-15 09:15:48 +0100502
kesavand7cf3a052020-08-28 12:49:18 +0530503 em.populateContextWithSerialDeviceID(context, onuInd.IntfId, onuInd.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100504
Devmalya Paulfb990a52019-07-09 10:01:49 -0400505 /* Populating device event body */
506 de.Context = context
507 de.ResourceId = deviceID
kesavand7cf3a052020-08-28 12:49:18 +0530508 de.DeviceEventName = eventName
Devmalya Paulfb990a52019-07-09 10:01:49 -0400509 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400510 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530511 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400512 }
kesavand7cf3a052020-08-28 12:49:18 +0530513 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 +0530514 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400515}
516
Neha Sharma96b7bf22020-06-15 10:37:32 +0000517func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400518 var de voltha.DeviceEvent
519 context := make(map[string]string)
520 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100521 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
522 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
523
524 em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
525
Devmalya Paulfb990a52019-07-09 10:01:49 -0400526 /* Populating device event body */
527 de.Context = context
528 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530529 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400530 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
531 } else {
532 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
533 }
534 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100535 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530536 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400537 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000538 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 +0530539 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400540}
541
Neha Sharma96b7bf22020-06-15 10:37:32 +0000542func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400543 var de voltha.DeviceEvent
544 context := make(map[string]string)
545 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100546 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
547 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
548 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
549 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
550
551 em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
552
Devmalya Paulfb990a52019-07-09 10:01:49 -0400553 /* Populating device event body */
554 de.Context = context
555 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530556 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400557 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
558 } else {
559 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
560 }
561 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100562 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530563 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400564 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000565 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 +0530566 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400567}
568
Neha Sharma96b7bf22020-06-15 10:37:32 +0000569func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400570 var de voltha.DeviceEvent
571 context := make(map[string]string)
572 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100573 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
574 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
575 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
576
577 em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
578
Devmalya Paulfb990a52019-07-09 10:01:49 -0400579 /* Populating device event body */
580 de.Context = context
581 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530582 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400583 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
584 } else {
585 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
586 }
587 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100588 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530589 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400590 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000591 logger.Debugw(ctx, "onu-signal-degrade-event-sent-to-kafka", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530592 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400593}
594
Neha Sharma96b7bf22020-06-15 10:37:32 +0000595func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400596 var de voltha.DeviceEvent
597 context := make(map[string]string)
598 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100599 em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
600
601 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
602 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
603 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400604 /* Populating device event body */
605 de.Context = context
606 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530607 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400608 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
609 } else {
610 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
611 }
612 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100613 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530614 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400615 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000616 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 +0530617 return nil
618}
619
Neha Sharma96b7bf22020-06-15 10:37:32 +0000620func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530621 var de voltha.DeviceEvent
622 context := make(map[string]string)
623 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100624 em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
625
626 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
627 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530628
629 /* Populating device event body */
630 de.Context = context
631 de.ResourceId = deviceID
632 if onuStartupFail.Status == statusCheckOn {
633 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
634 } else {
635 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
636 }
637 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400638 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530639 return err
640 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000641 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 +0530642 return nil
643}
644
Neha Sharma96b7bf22020-06-15 10:37:32 +0000645func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530646 var de voltha.DeviceEvent
647 context := make(map[string]string)
648 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100649 em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
650
651 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
652 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
Naga Manjunath9546b912019-11-28 20:56:20 +0530653 /* Populating device event body */
654 de.Context = context
655 de.ResourceId = deviceID
656 if onuLOKI.Status == statusCheckOn {
657 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
658 } else {
659 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
660 }
661
662 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400663 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530664 return err
665 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000666 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 +0530667 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400668}
kesavand39e0aa32020-01-28 20:58:50 -0500669
670// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Kent Hagermane6ff1012020-07-14 15:07:53 -0400671func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700672 portNo := plt.IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
khenaidoodc2116e2021-10-19 17:33:19 -0400673 if port, err := em.handler.getPortFromCore(ctx, &ca.PortFilter{
khenaidoo106c61a2021-08-11 18:05:46 -0400674 DeviceId: deviceID,
675 Port: portNo,
676 }); err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700677 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "err": err})
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400678 } else if port.AdminState != common.AdminState_ENABLED {
679 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 -0400680 return
kesavand39e0aa32020-01-28 20:58:50 -0500681 }
682 /* Populating event context */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400683 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
kesavand39e0aa32020-01-28 20:58:50 -0500684 /* Populating device event body */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400685 var de voltha.DeviceEvent
kesavand39e0aa32020-01-28 20:58:50 -0500686 de.Context = context
687 de.ResourceId = deviceID
688
689 if ifindication.GetOperState() == operationStateDown {
690 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
691 } else if ifindication.OperState == operationStateUp {
692 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
693 }
694 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400695 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
696 _ = 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)
697 return
kesavand39e0aa32020-01-28 20:58:50 -0500698 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000699 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
kesavand39e0aa32020-01-28 20:58:50 -0500700}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500701
Neha Sharma96b7bf22020-06-15 10:37:32 +0000702func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500703 var de voltha.DeviceEvent
704 context := make(map[string]string)
705 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100706 em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
707
708 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
709 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500710 /* Populating device event body */
711 de.Context = context
712 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400713 if onuDFI.Status == statusCheckOn {
714 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
715 } else {
716 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
717 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500718 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400719 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500720 return err
721 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000722 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 -0500723 return nil
724}
Amit Ghosh502056b2020-07-15 09:15:48 +0100725
Neha Sharma96b7bf22020-06-15 10:37:32 +0000726func (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 -0500727 /* Populating event context */
728 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100729 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
730 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
731 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500732 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100733 em.populateContextWithSerialDeviceID(context, intfID, onuID)
734
Devmalya Paul6f063a62020-02-19 19:19:06 -0500735 /* Populating device event body */
736 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400737 Context: context,
738 ResourceId: deviceID,
739 }
740 if status == statusCheckOn {
741 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
742 } else {
743 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500744 }
745 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400746 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500747 return err
748 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000749 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 -0400750 return nil
751}
752
Neha Sharma96b7bf22020-06-15 10:37:32 +0000753func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
Devmalya Paula1efa642020-04-20 01:36:43 -0400754 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
755 if !found {
756 return errors.New("unknown-onu-device")
757 }
758 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
759 if !onuDevice.(*OnuDevice).rdiRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000760 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400761 return err
762 }
763 onuDevice.(*OnuDevice).rdiRaised = true
764 return nil
765 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000766 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 -0400767 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000768 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400769 return err
770 }
771 onuDevice.(*OnuDevice).rdiRaised = false
772 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500773 return nil
774}
775
Neha Sharma96b7bf22020-06-15 10:37:32 +0000776func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500777 /* Populating event context */
778 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100779 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
780 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
781 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500782 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100783 em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
784
Devmalya Paul41a762d2020-03-01 18:56:54 -0500785 /* Populating device event body */
786 de := &voltha.DeviceEvent{
787 Context: context,
788 ResourceId: deviceID,
789 }
790 if onuGCD.Status == statusCheckOn {
791 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
792 } else {
793 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
794 }
795 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400796 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500797 return err
798 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000799 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 -0500800 return nil
801}
802
Neha Sharma96b7bf22020-06-15 10:37:32 +0000803func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500804 /* Populating event context */
805 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100806 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
807 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500808 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100809 em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500810 /* Populating device event body */
811 de := &voltha.DeviceEvent{
812 Context: context,
813 ResourceId: deviceID,
814 }
815 if onuErr.Status == statusCheckOn {
816 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
817 } else {
818 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
819 }
820 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400821 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500822 return err
823 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000824 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 -0500825 return nil
826}
827
Neha Sharma96b7bf22020-06-15 10:37:32 +0000828func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500829 /* Populating event context */
830 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100831 ContextOnuOnuID: strconv.FormatUint(uint64(onuLOA.OnuId), base10),
832 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500833 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100834 em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
835
Devmalya Paul41a762d2020-03-01 18:56:54 -0500836 /* Populating device event body */
837 de := &voltha.DeviceEvent{
838 Context: context,
839 ResourceId: deviceID,
840 }
841 if onuLOA.Status == statusCheckOn {
842 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
843 } else {
844 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
845 }
846 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400847 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500848 return err
849 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000850 logger.Debugw(ctx, "onu-physical-equipment-error-event-sent-to-kafka", log.Fields{"onu-id": onuLOA.OnuId, "intf-id": onuLOA.IntfId})
Devmalya Paul6f063a62020-02-19 19:19:06 -0500851 return nil
852}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400853
Neha Sharma96b7bf22020-06-15 10:37:32 +0000854func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400855 /* Populating event context */
856 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100857 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
858 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
859 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400860 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100861 em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
862
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400863 /* Populating device event body */
864 de := &voltha.DeviceEvent{
865 Context: context,
866 ResourceId: deviceID,
867 }
868 if onuDRE.Status == statusCheckOn {
869 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
870 } else {
871 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
872 }
873 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400874 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400875 return err
876 }
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000877 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 -0400878 return nil
879}