blob: db9ac177c29082ec09c3612b3d5d86e20445b709 [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 (
kesavand39e0aa32020-01-28 20:58:50 -050021 ctx "context"
Devmalya Paulfb990a52019-07-09 10:01:49 -040022 "fmt"
Naga Manjunath9546b912019-11-28 20:56:20 +053023 "strconv"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053024
Esin Karamanccb714b2019-11-29 15:02:06 +000025 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
26 "github.com/opencord/voltha-lib-go/v3/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053027 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
kesavand39e0aa32020-01-28 20:58:50 -050028 "github.com/opencord/voltha-protos/v3/go/common"
Esin Karamanccb714b2019-11-29 15:02:06 +000029 oop "github.com/opencord/voltha-protos/v3/go/openolt"
30 "github.com/opencord/voltha-protos/v3/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040031)
32
33const (
Devmalya Paul41a762d2020-03-01 18:56:54 -050034 onuDiscoveryEvent = "ONU_DISCOVERY"
35 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
36 onuLobEvent = "ONU_LOSS_OF_BURST"
37 onuLopcMissEvent = "ONU_LOPC_MISS"
38 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
39 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
40 oltIndicationDown = "OLT_DOWN_INDICATION"
41 onuDyingGaspEvent = "ONU_DYING_GASP"
42 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
43 onuStartupFailEvent = "ONU_STARTUP_FAIL"
44 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
45 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
46 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
47 onuProcessingErrorEvent = "ONU_PROCESSING_ERROR"
48 onuTiwiEvent = "ONU_TRANSMISSION_WARNING"
49 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
50 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
51 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
52 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
53 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
54 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
55 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
56 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
57 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
58 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Paulfb990a52019-07-09 10:01:49 -040059)
60
61const (
62 pon = voltha.EventSubCategory_PON
63 olt = voltha.EventSubCategory_OLT
64 ont = voltha.EventSubCategory_ONT
65 onu = voltha.EventSubCategory_ONU
66 nni = voltha.EventSubCategory_NNI
67 service = voltha.EventCategory_SERVICE
68 security = voltha.EventCategory_SECURITY
69 equipment = voltha.EventCategory_EQUIPMENT
70 processing = voltha.EventCategory_PROCESSING
71 environment = voltha.EventCategory_ENVIRONMENT
72 communication = voltha.EventCategory_COMMUNICATION
73)
74
Naga Manjunath9546b912019-11-28 20:56:20 +053075const (
76 // statusCheckOn represents status check On
77 statusCheckOn = "on"
78 // statusCheckOff represents status check Off
79 statusCheckOff = "off"
80 // operationStateUp represents operation state Up
81 operationStateUp = "up"
82 // operationStateDown represents operation state Down
83 operationStateDown = "down"
84 // base10 represents base 10 conversion
85 base10 = 10
86)
87
Devmalya Paulfb990a52019-07-09 10:01:49 -040088// OpenOltEventMgr struct contains
89type OpenOltEventMgr struct {
kdarapu381c6902019-07-31 18:23:16 +053090 eventProxy adapterif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040091 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -040092}
93
94// NewEventMgr is a Function to get a new event manager struct for the OpenOLT to process and publish OpenOLT event
Devmalya Paul90ca3012019-09-02 21:55:45 -040095func NewEventMgr(eventProxy adapterif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -040096 var em OpenOltEventMgr
97 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040098 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -040099 return &em
100}
101
102// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500103// nolint: gocyclo
David K. Bainbridge794735f2020-02-11 21:01:37 -0800104func (em *OpenOltEventMgr) ProcessEvents(alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530105 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400106 switch alarmInd.Data.(type) {
107 case *oop.AlarmIndication_LosInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000108 logger.Debugw("Received LOS indication", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530109 err = em.oltLosIndication(alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400110 case *oop.AlarmIndication_OnuAlarmInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000111 logger.Debugw("Received onu alarm indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530112 err = em.onuAlarmIndication(alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400113 case *oop.AlarmIndication_DyingGaspInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000114 logger.Debugw("Received dying gasp indication", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530115 err = em.onuDyingGaspIndication(alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400116 case *oop.AlarmIndication_OnuActivationFailInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000117 logger.Debugw("Received onu activation fail indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530118 err = em.onuActivationFailIndication(alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400119 case *oop.AlarmIndication_OnuLossOmciInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000120 logger.Debugw("Received onu loss omci indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530121 err = em.onuLossOmciIndication(alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400122 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000123 logger.Debugw("Received onu drift of window indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530124 err = em.onuDriftOfWindowIndication(alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400125 case *oop.AlarmIndication_OnuSignalDegradeInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000126 logger.Debugw("Received onu signal degrade indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530127 err = em.onuSignalDegradeIndication(alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400128 case *oop.AlarmIndication_OnuSignalsFailInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000129 logger.Debugw("Received onu signal fail indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530130 err = em.onuSignalsFailIndication(alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530131 case *oop.AlarmIndication_OnuStartupFailInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000132 logger.Debugw("Received onu startup fail indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunathf6f74642020-01-13 21:37:28 +0530133 err = em.onuStartupFailedIndication(alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400134 case *oop.AlarmIndication_OnuTiwiInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000135 logger.Debugw("Received onu transmission warning indication ", log.Fields{"alarm_ind": alarmInd})
136 logger.Debugw("Not implemented yet", log.Fields{"alarm_ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530137 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000138 logger.Debugw("Received onu Loss of Sync Fail indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530139 err = em.onuLossOfSyncIndication(alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
140 case *oop.AlarmIndication_OnuItuPonStatsInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000141 logger.Debugw("Received onu Itu Pon Stats indication ", log.Fields{"alarm_ind": alarmInd})
142 logger.Debugw("Not implemented yet", log.Fields{"alarm_ind": alarmInd})
Devmalya Paul6f063a62020-02-19 19:19:06 -0500143 case *oop.AlarmIndication_OnuRemoteDefectInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000144 logger.Debugw("Received onu remote defect indication ", log.Fields{"alarm_ind": alarmInd})
Devmalya Paul6f063a62020-02-19 19:19:06 -0500145 err = em.onuRemoteDefectIndication(alarmInd.GetOnuRemoteDefectInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500146 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000147 logger.Debugw("Received onu deactivation failure indication ", log.Fields{"alarm_ind": alarmInd})
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500148 err = em.onuDeactivationFailureIndication(alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500149 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000150 logger.Debugw("Received onu loss of GEM channel delineation indication ", log.Fields{"alarm_ind": alarmInd})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500151 err = em.onuLossOfGEMChannelDelineationIndication(alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
152 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000153 logger.Debugw("Received onu physical equipment error indication ", log.Fields{"alarm_ind": alarmInd})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500154 err = em.onuPhysicalEquipmentErrorIndication(alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
155 case *oop.AlarmIndication_OnuLossOfAckInd:
Girish Kumar2ad402b2020-03-20 19:45:12 +0000156 logger.Debugw("Received onu loss of acknowledgement indication ", log.Fields{"alarm_ind": alarmInd})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500157 err = em.onuLossOfAcknowledgementIndication(alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400158 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530159 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400160 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530161 if err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530162 return olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).Log()
Naga Manjunath9546b912019-11-28 20:56:20 +0530163 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800164 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400165}
166
Daniele Rossi051466a2019-07-26 13:39:37 +0000167// oltUpDownIndication handles Up and Down state of an OLT
Naga Manjunath9546b912019-11-28 20:56:20 +0530168func (em *OpenOltEventMgr) oltUpDownIndication(oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000169 var de voltha.DeviceEvent
170 context := make(map[string]string)
171 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530172 context["oper-state"] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000173 /* Populating device event body */
174 de.Context = context
175 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530176 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000177 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530178 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000179 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
180 }
181 /* Send event to KAFKA */
182 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000183 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000184 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000185 logger.Debugw("OLT UpDown event sent to KAFKA", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530186 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000187}
188
Devmalya Paulfb990a52019-07-09 10:01:49 -0400189// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Naga Manjunath9546b912019-11-28 20:56:20 +0530190func (em *OpenOltEventMgr) OnuDiscoveryIndication(onuDisc *oop.OnuDiscIndication, deviceID string, OnuID uint32, serialNumber string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400191 var de voltha.DeviceEvent
192 context := make(map[string]string)
193 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530194 context["onu-id"] = strconv.FormatUint(uint64(OnuID), base10)
195 context["intf-id"] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400196 context["serial-number"] = serialNumber
197 /* Populating device event body */
198 de.Context = context
199 de.ResourceId = deviceID
200 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
201 /* Send event to KAFKA */
202 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000203 return olterrors.NewErrCommunication("send-onu-discovery-event", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400204 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000205 logger.Debugw("ONU discovery event sent to KAFKA", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530206 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400207}
208
Naga Manjunath9546b912019-11-28 20:56:20 +0530209func (em *OpenOltEventMgr) oltLosIndication(oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530210 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400211 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530212 var alarmInd oop.OnuAlarmIndication
213 ponIntdID := PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
214
Devmalya Paulfb990a52019-07-09 10:01:49 -0400215 context := make(map[string]string)
216 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530217 context["intf-id"] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400218 /* Populating device event body */
219 de.Context = context
220 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530221 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400222 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530223
224 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
225 with "los_status: on" should be raised for each Onu connected to the PON
226 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
227 for all the ONU's connected to PON on receiving LoSIndication for PON */
228 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
229 if onuInCache.(*OnuDevice).intfID == ponIntdID {
230 alarmInd.IntfId = ponIntdID
231 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
232 alarmInd.LosStatus = statusCheckOn
233 err = em.onuAlarmIndication(&alarmInd, deviceID, raisedTs)
234 }
235 return true
236 })
237 if err != nil {
238 /* Return if any error encountered while processing ONU LoS Event*/
239 return err
240 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400241 } else {
242 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
243 }
244 /* Send event to KAFKA */
245 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530246 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400247 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000248 logger.Debugw("OLT LOS event sent to KAFKA", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530249 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400250}
251
Naga Manjunath9546b912019-11-28 20:56:20 +0530252func (em *OpenOltEventMgr) onuDyingGaspIndication(dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400253 var de voltha.DeviceEvent
Devmalya Paul90ca3012019-09-02 21:55:45 -0400254 var serialNumber string
Devmalya Paulfb990a52019-07-09 10:01:49 -0400255 context := make(map[string]string)
256 /* Populating event context */
Devmalya Paul90ca3012019-09-02 21:55:45 -0400257 serialNumber = ""
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530258 onu := em.handler.formOnuKey(dgi.IntfId, dgi.OnuId)
259 if onu, ok := em.handler.onus.Load(onu); ok {
260 serialNumber = onu.(*OnuDevice).serialNumber
Devmalya Paul90ca3012019-09-02 21:55:45 -0400261 }
262 context["serial-number"] = serialNumber
Naga Manjunath9546b912019-11-28 20:56:20 +0530263 context["intf-id"] = strconv.FormatUint(uint64(dgi.IntfId), base10)
264 context["onu-id"] = strconv.FormatUint(uint64(dgi.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400265 /* Populating device event body */
266 de.Context = context
267 de.ResourceId = deviceID
Thomas Lee Sf68399e2020-02-11 15:41:38 +0530268 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400269 /* Send event to KAFKA */
270 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530271 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400272 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000273 logger.Debugw("ONU dying gasp event sent to KAFKA", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530274 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400275}
276
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530277//wasLosRaised checks whether los raised already. If already raised returns true else false
278func (em *OpenOltEventMgr) wasLosRaised(onuAlarm *oop.OnuAlarmIndication) bool {
279 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
280 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000281 logger.Debugw("onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530282
283 if onuAlarm.LosStatus == statusCheckOn {
284 if onuInCache.(*OnuDevice).losRaised {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000285 logger.Warnw("onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530286 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
287 return true
288 }
289 return false
290 }
291 }
292 return true
293}
294
295//wasLosCleared checks whether los cleared already. If already cleared returns true else false
296func (em *OpenOltEventMgr) wasLosCleared(onuAlarm *oop.OnuAlarmIndication) bool {
297 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
298 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000299 logger.Debugw("onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530300
301 if onuAlarm.LosStatus == statusCheckOff {
302 if !onuInCache.(*OnuDevice).losRaised {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000303 logger.Warnw("onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530304 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
305 return true
306 }
307 return false
308 }
309 }
310 return true
311}
312
313func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
314 var deviceEventName string
315 if onuAlarm.LosStatus == statusCheckOn {
316 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
317 } else if onuAlarm.LosStatus == statusCheckOff {
318 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
319 } else if onuAlarm.LobStatus == statusCheckOn {
320 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
321 } else if onuAlarm.LobStatus == statusCheckOff {
322 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
323 } else if onuAlarm.LopcMissStatus == statusCheckOn {
324 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
325 } else if onuAlarm.LopcMissStatus == statusCheckOff {
326 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
327 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
328 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
329 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
330 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
331 } else if onuAlarm.LofiStatus == statusCheckOn {
332 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
333 } else if onuAlarm.LofiStatus == statusCheckOff {
334 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
335 } else if onuAlarm.LoamiStatus == statusCheckOn {
336 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
337 } else if onuAlarm.LoamiStatus == statusCheckOff {
338 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
339 }
340 return deviceEventName
341}
342
Naga Manjunath9546b912019-11-28 20:56:20 +0530343func (em *OpenOltEventMgr) onuAlarmIndication(onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400344 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530345 var serialNumber string
Devmalya Paulfb990a52019-07-09 10:01:49 -0400346 context := make(map[string]string)
347 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530348 context["intf-id"] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
349 context["onu-id"] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530350 serialNumber = ""
351 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
352 if onu, ok := em.handler.onus.Load(onuKey); ok {
353 serialNumber = onu.(*OnuDevice).serialNumber
354 }
355 context["serial-number"] = serialNumber
356
Devmalya Paulfb990a52019-07-09 10:01:49 -0400357 /* Populating device event body */
358 de.Context = context
359 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530360 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
361
362 switch onuAlarm.LosStatus {
363 case statusCheckOn:
364 if em.wasLosRaised(onuAlarm) {
365 /* No need to raise Onu Los Event as it might have already raised
366 or Onu might have deleted */
367 return nil
368 }
369 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
370 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
371 /* Update onu device with LoS raised state as true */
372 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
373 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
374 onuInCache.(*OnuDevice).proxyDeviceID, true))
375 }
376 case statusCheckOff:
377 if em.wasLosCleared(onuAlarm) {
378 /* No need to clear Onu Los Event as it might have already cleared
379 or Onu might have deleted */
380 return nil
381 }
382 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
383 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
384 /* Update onu device with LoS raised state as false */
385 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
386 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
387 onuInCache.(*OnuDevice).proxyDeviceID, false))
388 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400389 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530390
Devmalya Paulfb990a52019-07-09 10:01:49 -0400391 /* Send event to KAFKA */
392 if err := em.eventProxy.SendDeviceEvent(&de, communication, onu, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530393 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400394 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000395 logger.Debugw("ONU LOS event sent to KAFKA", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530396 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400397}
398
Naga Manjunath9546b912019-11-28 20:56:20 +0530399func (em *OpenOltEventMgr) onuActivationFailIndication(oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400400 var de voltha.DeviceEvent
401 context := make(map[string]string)
402 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530403 context["intf-id"] = strconv.FormatUint(uint64(oaf.IntfId), base10)
404 context["onu-id"] = strconv.FormatUint(uint64(oaf.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800405 context["fail-reason"] = strconv.FormatUint(uint64(oaf.FailReason), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400406 /* Populating device event body */
407 de.Context = context
408 de.ResourceId = deviceID
409 de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
410 /* Send event to KAFKA */
411 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530412 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400413 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000414 logger.Debugw("ONU activation failure event sent to KAFKA", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530415 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400416}
417
Naga Manjunath9546b912019-11-28 20:56:20 +0530418func (em *OpenOltEventMgr) onuLossOmciIndication(onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400419 var de voltha.DeviceEvent
420 context := make(map[string]string)
421 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530422 context["intf-id"] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
423 context["onu-id"] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400424 /* Populating device event body */
425 de.Context = context
426 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530427 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400428 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
429 } else {
430 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
431 }
432 /* Send event to KAFKA */
433 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530434 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400435 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000436 logger.Debugw("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 +0530437 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400438}
439
Naga Manjunath9546b912019-11-28 20:56:20 +0530440func (em *OpenOltEventMgr) onuDriftOfWindowIndication(onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400441 var de voltha.DeviceEvent
442 context := make(map[string]string)
443 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530444 context["intf-id"] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
445 context["onu-id"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800446 context["drift"] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
447 context["new-eqd"] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400448 /* Populating device event body */
449 de.Context = context
450 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530451 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400452 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
453 } else {
454 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
455 }
456 /* Send event to KAFKA */
457 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530458 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400459 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000460 logger.Debugw("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 +0530461 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400462}
463
Naga Manjunath9546b912019-11-28 20:56:20 +0530464func (em *OpenOltEventMgr) onuSignalDegradeIndication(onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400465 var de voltha.DeviceEvent
466 context := make(map[string]string)
467 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530468 context["intf-id"] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
469 context["onu-id"] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800470 context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400471 /* Populating device event body */
472 de.Context = context
473 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530474 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400475 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
476 } else {
477 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
478 }
479 /* Send event to KAFKA */
480 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530481 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400482 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000483 logger.Debugw("ONU signal degrade event sent to KAFKA", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530484 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400485}
486
Naga Manjunath9546b912019-11-28 20:56:20 +0530487func (em *OpenOltEventMgr) onuSignalsFailIndication(onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400488 var de voltha.DeviceEvent
489 context := make(map[string]string)
490 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530491 context["onu-id"] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
492 context["intf-id"] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
493 context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400494 /* Populating device event body */
495 de.Context = context
496 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530497 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400498 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
499 } else {
500 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
501 }
502 /* Send event to KAFKA */
503 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530504 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400505 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000506 logger.Debugw("ONU signals fail event sent to KAFKA", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530507 return nil
508}
509
Naga Manjunathf6f74642020-01-13 21:37:28 +0530510func (em *OpenOltEventMgr) onuStartupFailedIndication(onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
511 var de voltha.DeviceEvent
512 context := make(map[string]string)
513 /* Populating event context */
514 context["onu-id"] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
515 context["intf-id"] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
516
517 /* Populating device event body */
518 de.Context = context
519 de.ResourceId = deviceID
520 if onuStartupFail.Status == statusCheckOn {
521 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
522 } else {
523 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
524 }
525 /* Send event to KAFKA */
526 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530527 return err
528 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000529 logger.Debugw("ONU startup fail event sent to KAFKA", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId})
Naga Manjunathf6f74642020-01-13 21:37:28 +0530530 return nil
531}
532
Naga Manjunath9546b912019-11-28 20:56:20 +0530533func (em *OpenOltEventMgr) onuLossOfSyncIndication(onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
534 var de voltha.DeviceEvent
535 context := make(map[string]string)
536 /* Populating event context */
537 context["onu-id"] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
538 context["intf-id"] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
539 /* Populating device event body */
540 de.Context = context
541 de.ResourceId = deviceID
542 if onuLOKI.Status == statusCheckOn {
543 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
544 } else {
545 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
546 }
547
548 /* Send event to KAFKA */
549 if err := em.eventProxy.SendDeviceEvent(&de, security, onu, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530550 return err
551 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000552 logger.Debugw("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 +0530553 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400554}
kesavand39e0aa32020-01-28 20:58:50 -0500555
556// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Devmalya Paul24400472020-03-12 19:26:02 -0400557func (em *OpenOltEventMgr) oltIntfOperIndication(ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) error {
kesavand39e0aa32020-01-28 20:58:50 -0500558 var de voltha.DeviceEvent
559 context := make(map[string]string)
560 portID := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
561 device, err := em.handler.coreProxy.GetDevice(ctx.Background(), deviceID, deviceID)
562 if err != nil {
Devmalya Paul24400472020-03-12 19:26:02 -0400563 return olterrors.NewErrAdapter("Error while fetching Device object", log.Fields{"DeviceId": deviceID}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500564 }
565 for _, port := range device.Ports {
566 if port.PortNo == portID {
567 // Events are suppressed if the Port Adminstate is not enabled.
568 if port.AdminState != common.AdminState_ENABLED {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000569 logger.Debugw("Port disable/enable event not generated because, The port is not enabled by operator", log.Fields{"deviceId": deviceID, "port": port})
Devmalya Paul24400472020-03-12 19:26:02 -0400570 return nil
kesavand39e0aa32020-01-28 20:58:50 -0500571 }
572 break
573 }
574 }
575 /* Populating event context */
576 context["oper-state"] = ifindication.GetOperState()
577 /* Populating device event body */
578 de.Context = context
579 de.ResourceId = deviceID
580
581 if ifindication.GetOperState() == operationStateDown {
582 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
583 } else if ifindication.OperState == operationStateUp {
584 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
585 }
586 /* Send event to KAFKA */
587 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
Devmalya Paul24400472020-03-12 19:26:02 -0400588 return olterrors.NewErrCommunication("send-olt-intf-oper-status-event", log.Fields{"device-id": deviceID, "intf-id": ifindication.IntfId, "oper-state": ifindication.OperState}, err).Log()
kesavand39e0aa32020-01-28 20:58:50 -0500589 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000590 logger.Debug("sent-olt-intf-oper-status-event-to-kafka")
Devmalya Paul24400472020-03-12 19:26:02 -0400591 return nil
kesavand39e0aa32020-01-28 20:58:50 -0500592}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500593
594func (em *OpenOltEventMgr) onuDeactivationFailureIndication(onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
595 var de voltha.DeviceEvent
596 context := make(map[string]string)
597 /* Populating event context */
598 context["onu-id"] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
599 context["intf-id"] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
600 context["failure-reason"] = strconv.FormatUint(uint64(onuDFI.FailReason), base10)
601 /* Populating device event body */
602 de.Context = context
603 de.ResourceId = deviceID
604 de.DeviceEventName = onuDeactivationFailureEvent
605
606 /* Send event to KAFKA */
607 if err := em.eventProxy.SendDeviceEvent(&de, equipment, onu, raisedTs); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500608 return err
609 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000610 logger.Debugw("ONU deactivation failure event sent to KAFKA", log.Fields{"onu-id": onuDFI.OnuId, "intf-id": onuDFI.IntfId})
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500611 return nil
612}
Devmalya Paul6f063a62020-02-19 19:19:06 -0500613
614func (em *OpenOltEventMgr) onuRemoteDefectIndication(onuRDI *oop.OnuRemoteDefectIndication, deviceID string, raisedTs int64) error {
615 /* Populating event context */
616 context := map[string]string{
617 "onu-id": strconv.FormatUint(uint64(onuRDI.OnuId), base10),
618 "intf-id": strconv.FormatUint(uint64(onuRDI.IntfId), base10),
619 "rdi-errors": strconv.FormatUint(uint64(onuRDI.RdiErrors), base10),
620 }
621 /* Populating device event body */
622 de := &voltha.DeviceEvent{
623 Context: context,
624 ResourceId: deviceID,
625 DeviceEventName: onuRemoteDefectIndication,
626 }
627 /* Send event to KAFKA */
628 if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500629 return err
630 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000631 logger.Debugw("ONU remote defect event sent to KAFKA", log.Fields{"onu-id": onuRDI.OnuId, "intf-id": onuRDI.IntfId})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500632 return nil
633}
634
635func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
636 /* Populating event context */
637 context := map[string]string{
638 "onu-id": strconv.FormatUint(uint64(onuGCD.OnuId), base10),
639 "intf-id": strconv.FormatUint(uint64(onuGCD.IntfId), base10),
640 "delineation-errors": strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
641 }
642 /* Populating device event body */
643 de := &voltha.DeviceEvent{
644 Context: context,
645 ResourceId: deviceID,
646 }
647 if onuGCD.Status == statusCheckOn {
648 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
649 } else {
650 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
651 }
652 /* Send event to KAFKA */
653 if err := em.eventProxy.SendDeviceEvent(de, communication, onu, raisedTs); err != nil {
654 return err
655 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000656 logger.Debugw("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 -0500657 return nil
658}
659
660func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
661 /* Populating event context */
662 context := map[string]string{
663 "onu-id": strconv.FormatUint(uint64(onuErr.OnuId), base10),
664 "intf-id": strconv.FormatUint(uint64(onuErr.IntfId), base10),
665 }
666 /* Populating device event body */
667 de := &voltha.DeviceEvent{
668 Context: context,
669 ResourceId: deviceID,
670 }
671 if onuErr.Status == statusCheckOn {
672 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
673 } else {
674 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
675 }
676 /* Send event to KAFKA */
677 if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil {
678 return err
679 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000680 logger.Debugw("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 -0500681 return nil
682}
683
684func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
685 /* Populating event context */
686 context := map[string]string{
687 "onu-id": strconv.FormatUint(uint64(onuLOA.OnuId), base10),
688 "intf-id": strconv.FormatUint(uint64(onuLOA.IntfId), base10),
689 }
690 /* Populating device event body */
691 de := &voltha.DeviceEvent{
692 Context: context,
693 ResourceId: deviceID,
694 }
695 if onuLOA.Status == statusCheckOn {
696 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
697 } else {
698 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
699 }
700 /* Send event to KAFKA */
701 if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil {
702 return err
703 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000704 logger.Debugw("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 -0500705 return nil
706}