blob: a11d3f7c8b5781c6266cadd4a71655a0e8f80f03 [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 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
Esin Karamanccb714b2019-11-29 15:02:06 +000026 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
27 "github.com/opencord/voltha-lib-go/v3/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053028 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
kesavand39e0aa32020-01-28 20:58:50 -050029 "github.com/opencord/voltha-protos/v3/go/common"
Esin Karamanccb714b2019-11-29 15:02:06 +000030 oop "github.com/opencord/voltha-protos/v3/go/openolt"
31 "github.com/opencord/voltha-protos/v3/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040032)
33
34const (
Devmalya Paul41a762d2020-03-01 18:56:54 -050035 onuDiscoveryEvent = "ONU_DISCOVERY"
36 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
37 onuLobEvent = "ONU_LOSS_OF_BURST"
38 onuLopcMissEvent = "ONU_LOPC_MISS"
39 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
40 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
41 oltIndicationDown = "OLT_DOWN_INDICATION"
42 onuDyingGaspEvent = "ONU_DYING_GASP"
43 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
44 onuStartupFailEvent = "ONU_STARTUP_FAIL"
45 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
46 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
47 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
48 onuProcessingErrorEvent = "ONU_PROCESSING_ERROR"
49 onuTiwiEvent = "ONU_TRANSMISSION_WARNING"
50 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
51 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
52 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
53 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
54 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
55 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
56 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
57 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
58 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
59 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Pauleb5294e2020-03-19 03:01:39 -040060 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
Devmalya Paulfb990a52019-07-09 10:01:49 -040061)
62
63const (
64 pon = voltha.EventSubCategory_PON
65 olt = voltha.EventSubCategory_OLT
66 ont = voltha.EventSubCategory_ONT
67 onu = voltha.EventSubCategory_ONU
68 nni = voltha.EventSubCategory_NNI
69 service = voltha.EventCategory_SERVICE
70 security = voltha.EventCategory_SECURITY
71 equipment = voltha.EventCategory_EQUIPMENT
72 processing = voltha.EventCategory_PROCESSING
73 environment = voltha.EventCategory_ENVIRONMENT
74 communication = voltha.EventCategory_COMMUNICATION
75)
76
Naga Manjunath9546b912019-11-28 20:56:20 +053077const (
78 // statusCheckOn represents status check On
79 statusCheckOn = "on"
80 // statusCheckOff represents status check Off
81 statusCheckOff = "off"
82 // operationStateUp represents operation state Up
83 operationStateUp = "up"
84 // operationStateDown represents operation state Down
85 operationStateDown = "down"
86 // base10 represents base 10 conversion
87 base10 = 10
88)
89
Devmalya Paulfb990a52019-07-09 10:01:49 -040090// OpenOltEventMgr struct contains
91type OpenOltEventMgr struct {
kdarapu381c6902019-07-31 18:23:16 +053092 eventProxy adapterif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040093 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -040094}
95
96// 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 -040097func NewEventMgr(eventProxy adapterif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -040098 var em OpenOltEventMgr
99 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400100 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400101 return &em
102}
103
104// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500105// nolint: gocyclo
David K. Bainbridge794735f2020-02-11 21:01:37 -0800106func (em *OpenOltEventMgr) ProcessEvents(alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530107 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400108 switch alarmInd.Data.(type) {
109 case *oop.AlarmIndication_LosInd:
Shrey Baid26912972020-04-16 21:02:31 +0530110 logger.Debugw("received-los-indication", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530111 err = em.oltLosIndication(alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400112 case *oop.AlarmIndication_OnuAlarmInd:
Shrey Baid26912972020-04-16 21:02:31 +0530113 logger.Debugw("received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530114 err = em.onuAlarmIndication(alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400115 case *oop.AlarmIndication_DyingGaspInd:
Shrey Baid26912972020-04-16 21:02:31 +0530116 logger.Debugw("received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530117 err = em.onuDyingGaspIndication(alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400118 case *oop.AlarmIndication_OnuActivationFailInd:
Shrey Baid26912972020-04-16 21:02:31 +0530119 logger.Debugw("received-onu-activation-fail-indication ", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530120 err = em.onuActivationFailIndication(alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400121 case *oop.AlarmIndication_OnuLossOmciInd:
Shrey Baid26912972020-04-16 21:02:31 +0530122 logger.Debugw("received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530123 err = em.onuLossOmciIndication(alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400124 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Shrey Baid26912972020-04-16 21:02:31 +0530125 logger.Debugw("received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530126 err = em.onuDriftOfWindowIndication(alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400127 case *oop.AlarmIndication_OnuSignalDegradeInd:
Shrey Baid26912972020-04-16 21:02:31 +0530128 logger.Debugw("received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530129 err = em.onuSignalDegradeIndication(alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400130 case *oop.AlarmIndication_OnuSignalsFailInd:
Shrey Baid26912972020-04-16 21:02:31 +0530131 logger.Debugw("received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530132 err = em.onuSignalsFailIndication(alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530133 case *oop.AlarmIndication_OnuStartupFailInd:
Shrey Baid26912972020-04-16 21:02:31 +0530134 logger.Debugw("received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
Naga Manjunathf6f74642020-01-13 21:37:28 +0530135 err = em.onuStartupFailedIndication(alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400136 case *oop.AlarmIndication_OnuTiwiInd:
Shrey Baid26912972020-04-16 21:02:31 +0530137 logger.Debugw("received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
138 logger.Warnw("not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530139 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Shrey Baid26912972020-04-16 21:02:31 +0530140 logger.Debugw("received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530141 err = em.onuLossOfSyncIndication(alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
142 case *oop.AlarmIndication_OnuItuPonStatsInd:
Shrey Baid26912972020-04-16 21:02:31 +0530143 logger.Debugw("received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
Devmalya Paula1efa642020-04-20 01:36:43 -0400144 err = em.onuItuPonStatsIndication(alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500145 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Shrey Baid26912972020-04-16 21:02:31 +0530146 logger.Debugw("received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500147 err = em.onuDeactivationFailureIndication(alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500148 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Shrey Baid26912972020-04-16 21:02:31 +0530149 logger.Debugw("received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500150 err = em.onuLossOfGEMChannelDelineationIndication(alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
151 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Shrey Baid26912972020-04-16 21:02:31 +0530152 logger.Debugw("received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500153 err = em.onuPhysicalEquipmentErrorIndication(alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
154 case *oop.AlarmIndication_OnuLossOfAckInd:
Shrey Baid26912972020-04-16 21:02:31 +0530155 logger.Debugw("received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500156 err = em.onuLossOfAcknowledgementIndication(alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400157 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Shrey Baid26912972020-04-16 21:02:31 +0530158 logger.Debugw("received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400159 err = em.onuDifferentialReachExceededIndication(alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400160 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530161 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400162 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530163 if err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530164 return olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).Log()
Naga Manjunath9546b912019-11-28 20:56:20 +0530165 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800166 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400167}
168
Daniele Rossi051466a2019-07-26 13:39:37 +0000169// oltUpDownIndication handles Up and Down state of an OLT
Naga Manjunath9546b912019-11-28 20:56:20 +0530170func (em *OpenOltEventMgr) oltUpDownIndication(oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000171 var de voltha.DeviceEvent
172 context := make(map[string]string)
173 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530174 context["oper-state"] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000175 /* Populating device event body */
176 de.Context = context
177 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530178 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000179 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530180 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000181 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
182 }
183 /* Send event to KAFKA */
184 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000185 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000186 }
Shrey Baid26912972020-04-16 21:02:31 +0530187 logger.Debugw("olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530188 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000189}
190
Devmalya Paulfb990a52019-07-09 10:01:49 -0400191// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Amit Ghosh75f0e292020-05-14 11:31:54 +0100192func (em *OpenOltEventMgr) OnuDiscoveryIndication(onuDisc *oop.OnuDiscIndication, oltDeviceID string, onuDeviceID string, OnuID uint32, serialNumber string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400193 var de voltha.DeviceEvent
194 context := make(map[string]string)
195 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530196 context["onu-id"] = strconv.FormatUint(uint64(OnuID), base10)
197 context["intf-id"] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400198 context["serial-number"] = serialNumber
Amit Ghosh75f0e292020-05-14 11:31:54 +0100199 context["onu-device-id"] = onuDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400200 /* Populating device event body */
201 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100202 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400203 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
204 /* Send event to KAFKA */
205 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530206 return olterrors.NewErrCommunication("send-onu-discovery-event",
207 log.Fields{
208 "serial-number": serialNumber,
209 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400210 }
Shrey Baid26912972020-04-16 21:02:31 +0530211 logger.Debugw("onu-discovery-event-sent-to-kafka",
212 log.Fields{
213 "serial-number": serialNumber,
214 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530215 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400216}
217
Naga Manjunath9546b912019-11-28 20:56:20 +0530218func (em *OpenOltEventMgr) oltLosIndication(oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530219 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400220 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530221 var alarmInd oop.OnuAlarmIndication
222 ponIntdID := PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
223
Devmalya Paulfb990a52019-07-09 10:01:49 -0400224 context := make(map[string]string)
225 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530226 context["intf-id"] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400227 /* Populating device event body */
228 de.Context = context
229 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530230 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400231 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530232
233 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
234 with "los_status: on" should be raised for each Onu connected to the PON
235 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
236 for all the ONU's connected to PON on receiving LoSIndication for PON */
237 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
238 if onuInCache.(*OnuDevice).intfID == ponIntdID {
239 alarmInd.IntfId = ponIntdID
240 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
241 alarmInd.LosStatus = statusCheckOn
242 err = em.onuAlarmIndication(&alarmInd, deviceID, raisedTs)
243 }
244 return true
245 })
246 if err != nil {
247 /* Return if any error encountered while processing ONU LoS Event*/
248 return err
249 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400250 } else {
251 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
252 }
253 /* Send event to KAFKA */
254 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530255 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400256 }
Shrey Baid26912972020-04-16 21:02:31 +0530257 logger.Debugw("olt-los-event-sent-to-kafka", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530258 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400259}
260
Naga Manjunath9546b912019-11-28 20:56:20 +0530261func (em *OpenOltEventMgr) onuDyingGaspIndication(dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400262 var de voltha.DeviceEvent
Devmalya Paul90ca3012019-09-02 21:55:45 -0400263 var serialNumber string
Devmalya Paulfb990a52019-07-09 10:01:49 -0400264 context := make(map[string]string)
265 /* Populating event context */
Devmalya Paul90ca3012019-09-02 21:55:45 -0400266 serialNumber = ""
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530267 onu := em.handler.formOnuKey(dgi.IntfId, dgi.OnuId)
268 if onu, ok := em.handler.onus.Load(onu); ok {
269 serialNumber = onu.(*OnuDevice).serialNumber
Devmalya Paul90ca3012019-09-02 21:55:45 -0400270 }
271 context["serial-number"] = serialNumber
Naga Manjunath9546b912019-11-28 20:56:20 +0530272 context["intf-id"] = strconv.FormatUint(uint64(dgi.IntfId), base10)
273 context["onu-id"] = strconv.FormatUint(uint64(dgi.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400274 /* Populating device event body */
275 de.Context = context
276 de.ResourceId = deviceID
Thomas Lee Sf68399e2020-02-11 15:41:38 +0530277 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400278 /* Send event to KAFKA */
279 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530280 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400281 }
Shrey Baid26912972020-04-16 21:02:31 +0530282 logger.Debugw("onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530283 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400284}
285
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530286//wasLosRaised checks whether los raised already. If already raised returns true else false
287func (em *OpenOltEventMgr) wasLosRaised(onuAlarm *oop.OnuAlarmIndication) bool {
288 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
289 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000290 logger.Debugw("onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530291
292 if onuAlarm.LosStatus == statusCheckOn {
293 if onuInCache.(*OnuDevice).losRaised {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000294 logger.Warnw("onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530295 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
296 return true
297 }
298 return false
299 }
300 }
301 return true
302}
303
304//wasLosCleared checks whether los cleared already. If already cleared returns true else false
305func (em *OpenOltEventMgr) wasLosCleared(onuAlarm *oop.OnuAlarmIndication) bool {
306 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
307 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000308 logger.Debugw("onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530309
310 if onuAlarm.LosStatus == statusCheckOff {
311 if !onuInCache.(*OnuDevice).losRaised {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000312 logger.Warnw("onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530313 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
314 return true
315 }
316 return false
317 }
318 }
319 return true
320}
321
322func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
323 var deviceEventName string
324 if onuAlarm.LosStatus == statusCheckOn {
325 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
326 } else if onuAlarm.LosStatus == statusCheckOff {
327 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
328 } else if onuAlarm.LobStatus == statusCheckOn {
329 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
330 } else if onuAlarm.LobStatus == statusCheckOff {
331 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
332 } else if onuAlarm.LopcMissStatus == statusCheckOn {
333 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
334 } else if onuAlarm.LopcMissStatus == statusCheckOff {
335 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
336 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
337 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
338 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
339 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
340 } else if onuAlarm.LofiStatus == statusCheckOn {
341 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
342 } else if onuAlarm.LofiStatus == statusCheckOff {
343 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
344 } else if onuAlarm.LoamiStatus == statusCheckOn {
345 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
346 } else if onuAlarm.LoamiStatus == statusCheckOff {
347 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
348 }
349 return deviceEventName
350}
351
Naga Manjunath9546b912019-11-28 20:56:20 +0530352func (em *OpenOltEventMgr) onuAlarmIndication(onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400353 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530354 var serialNumber string
Devmalya Paulfb990a52019-07-09 10:01:49 -0400355 context := make(map[string]string)
356 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530357 context["intf-id"] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
358 context["onu-id"] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530359 serialNumber = ""
360 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
361 if onu, ok := em.handler.onus.Load(onuKey); ok {
362 serialNumber = onu.(*OnuDevice).serialNumber
363 }
364 context["serial-number"] = serialNumber
365
Devmalya Paulfb990a52019-07-09 10:01:49 -0400366 /* Populating device event body */
367 de.Context = context
368 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530369 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
370
371 switch onuAlarm.LosStatus {
372 case statusCheckOn:
373 if em.wasLosRaised(onuAlarm) {
374 /* No need to raise Onu Los Event as it might have already raised
375 or Onu might have deleted */
376 return nil
377 }
378 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
379 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
380 /* Update onu device with LoS raised state as true */
381 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
382 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
383 onuInCache.(*OnuDevice).proxyDeviceID, true))
384 }
385 case statusCheckOff:
386 if em.wasLosCleared(onuAlarm) {
387 /* No need to clear Onu Los Event as it might have already cleared
388 or Onu might have deleted */
389 return nil
390 }
391 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
392 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
393 /* Update onu device with LoS raised state as false */
394 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
395 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
396 onuInCache.(*OnuDevice).proxyDeviceID, false))
397 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400398 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530399
Devmalya Paulfb990a52019-07-09 10:01:49 -0400400 /* Send event to KAFKA */
401 if err := em.eventProxy.SendDeviceEvent(&de, communication, onu, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530402 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400403 }
Shrey Baid26912972020-04-16 21:02:31 +0530404 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 +0530405 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400406}
407
Naga Manjunath9546b912019-11-28 20:56:20 +0530408func (em *OpenOltEventMgr) onuActivationFailIndication(oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400409 var de voltha.DeviceEvent
410 context := make(map[string]string)
411 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530412 context["intf-id"] = strconv.FormatUint(uint64(oaf.IntfId), base10)
413 context["onu-id"] = strconv.FormatUint(uint64(oaf.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800414 context["fail-reason"] = strconv.FormatUint(uint64(oaf.FailReason), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400415 /* Populating device event body */
416 de.Context = context
417 de.ResourceId = deviceID
418 de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
419 /* Send event to KAFKA */
420 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530421 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400422 }
Shrey Baid26912972020-04-16 21:02:31 +0530423 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 +0530424 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400425}
426
Naga Manjunath9546b912019-11-28 20:56:20 +0530427func (em *OpenOltEventMgr) onuLossOmciIndication(onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400428 var de voltha.DeviceEvent
429 context := make(map[string]string)
430 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530431 context["intf-id"] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
432 context["onu-id"] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400433 /* Populating device event body */
434 de.Context = context
435 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530436 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400437 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
438 } else {
439 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
440 }
441 /* Send event to KAFKA */
442 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530443 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400444 }
Shrey Baid26912972020-04-16 21:02:31 +0530445 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 +0530446 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400447}
448
Naga Manjunath9546b912019-11-28 20:56:20 +0530449func (em *OpenOltEventMgr) onuDriftOfWindowIndication(onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400450 var de voltha.DeviceEvent
451 context := make(map[string]string)
452 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530453 context["intf-id"] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
454 context["onu-id"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800455 context["drift"] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
456 context["new-eqd"] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400457 /* Populating device event body */
458 de.Context = context
459 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530460 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400461 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
462 } else {
463 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
464 }
465 /* Send event to KAFKA */
466 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530467 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400468 }
Shrey Baid26912972020-04-16 21:02:31 +0530469 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 +0530470 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400471}
472
Naga Manjunath9546b912019-11-28 20:56:20 +0530473func (em *OpenOltEventMgr) onuSignalDegradeIndication(onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400474 var de voltha.DeviceEvent
475 context := make(map[string]string)
476 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530477 context["intf-id"] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
478 context["onu-id"] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800479 context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400480 /* Populating device event body */
481 de.Context = context
482 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530483 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400484 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
485 } else {
486 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
487 }
488 /* Send event to KAFKA */
489 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530490 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400491 }
Shrey Baid26912972020-04-16 21:02:31 +0530492 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 +0530493 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400494}
495
Naga Manjunath9546b912019-11-28 20:56:20 +0530496func (em *OpenOltEventMgr) onuSignalsFailIndication(onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400497 var de voltha.DeviceEvent
498 context := make(map[string]string)
499 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530500 context["onu-id"] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
501 context["intf-id"] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
502 context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400503 /* Populating device event body */
504 de.Context = context
505 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530506 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400507 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
508 } else {
509 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
510 }
511 /* Send event to KAFKA */
512 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530513 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400514 }
Shrey Baid26912972020-04-16 21:02:31 +0530515 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 +0530516 return nil
517}
518
Naga Manjunathf6f74642020-01-13 21:37:28 +0530519func (em *OpenOltEventMgr) onuStartupFailedIndication(onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
520 var de voltha.DeviceEvent
521 context := make(map[string]string)
522 /* Populating event context */
523 context["onu-id"] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
524 context["intf-id"] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
525
526 /* Populating device event body */
527 de.Context = context
528 de.ResourceId = deviceID
529 if onuStartupFail.Status == statusCheckOn {
530 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
531 } else {
532 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
533 }
534 /* Send event to KAFKA */
535 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530536 return err
537 }
Shrey Baid26912972020-04-16 21:02:31 +0530538 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 +0530539 return nil
540}
541
Naga Manjunath9546b912019-11-28 20:56:20 +0530542func (em *OpenOltEventMgr) onuLossOfSyncIndication(onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
543 var de voltha.DeviceEvent
544 context := make(map[string]string)
545 /* Populating event context */
546 context["onu-id"] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
547 context["intf-id"] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
548 /* Populating device event body */
549 de.Context = context
550 de.ResourceId = deviceID
551 if onuLOKI.Status == statusCheckOn {
552 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
553 } else {
554 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
555 }
556
557 /* Send event to KAFKA */
558 if err := em.eventProxy.SendDeviceEvent(&de, security, onu, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530559 return err
560 }
Shrey Baid26912972020-04-16 21:02:31 +0530561 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 +0530562 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400563}
kesavand39e0aa32020-01-28 20:58:50 -0500564
565// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Devmalya Paul24400472020-03-12 19:26:02 -0400566func (em *OpenOltEventMgr) oltIntfOperIndication(ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) error {
kesavand39e0aa32020-01-28 20:58:50 -0500567 var de voltha.DeviceEvent
568 context := make(map[string]string)
569 portID := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
570 device, err := em.handler.coreProxy.GetDevice(ctx.Background(), deviceID, deviceID)
571 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530572 return olterrors.NewErrAdapter("error-while-fetching-device-object", log.Fields{"DeviceId": deviceID}, err)
kesavand39e0aa32020-01-28 20:58:50 -0500573 }
574 for _, port := range device.Ports {
575 if port.PortNo == portID {
576 // Events are suppressed if the Port Adminstate is not enabled.
577 if port.AdminState != common.AdminState_ENABLED {
Shrey Baid26912972020-04-16 21:02:31 +0530578 logger.Debugw("port-disable/enable-event-not-generated--the-port-is-not-enabled-by-operator", log.Fields{"deviceId": deviceID, "port": port})
Devmalya Paul24400472020-03-12 19:26:02 -0400579 return nil
kesavand39e0aa32020-01-28 20:58:50 -0500580 }
581 break
582 }
583 }
584 /* Populating event context */
585 context["oper-state"] = ifindication.GetOperState()
586 /* Populating device event body */
587 de.Context = context
588 de.ResourceId = deviceID
589
590 if ifindication.GetOperState() == operationStateDown {
591 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
592 } else if ifindication.OperState == operationStateUp {
593 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
594 }
595 /* Send event to KAFKA */
596 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
Devmalya Paul24400472020-03-12 19:26:02 -0400597 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 -0500598 }
Girish Kumar2ad402b2020-03-20 19:45:12 +0000599 logger.Debug("sent-olt-intf-oper-status-event-to-kafka")
Devmalya Paul24400472020-03-12 19:26:02 -0400600 return nil
kesavand39e0aa32020-01-28 20:58:50 -0500601}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500602
603func (em *OpenOltEventMgr) onuDeactivationFailureIndication(onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
604 var de voltha.DeviceEvent
605 context := make(map[string]string)
606 /* Populating event context */
607 context["onu-id"] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
608 context["intf-id"] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500609 /* Populating device event body */
610 de.Context = context
611 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400612 if onuDFI.Status == statusCheckOn {
613 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
614 } else {
615 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
616 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500617 /* Send event to KAFKA */
618 if err := em.eventProxy.SendDeviceEvent(&de, equipment, onu, raisedTs); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500619 return err
620 }
Shrey Baid26912972020-04-16 21:02:31 +0530621 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 -0500622 return nil
623}
Devmalya Paula1efa642020-04-20 01:36:43 -0400624func (em *OpenOltEventMgr) onuRemoteDefectIndication(onuID uint32, intfID uint32, rdiCount uint64, status string, deviceID string, raisedTs int64) error {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500625 /* Populating event context */
626 context := map[string]string{
Devmalya Paula1efa642020-04-20 01:36:43 -0400627 "onu-id": strconv.FormatUint(uint64(onuID), base10),
628 "intf-id": strconv.FormatUint(uint64(intfID), base10),
629 "rdi-count": strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500630 }
631 /* Populating device event body */
632 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400633 Context: context,
634 ResourceId: deviceID,
635 }
636 if status == statusCheckOn {
637 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
638 } else {
639 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500640 }
641 /* Send event to KAFKA */
642 if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500643 return err
644 }
Devmalya Paula1efa642020-04-20 01:36:43 -0400645 logger.Debugw("onu-remote-defect-event-sent-to-kafka", log.Fields{"onu-id": onuID, "intf-id": intfID})
646 return nil
647}
648
649func (em *OpenOltEventMgr) onuItuPonStatsIndication(onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
650 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
651 if !found {
652 return errors.New("unknown-onu-device")
653 }
654 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
655 if !onuDevice.(*OnuDevice).rdiRaised {
656 if err := em.onuRemoteDefectIndication(onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
657 return err
658 }
659 onuDevice.(*OnuDevice).rdiRaised = true
660 return nil
661 }
662 logger.Debugw("onu-remote-defect-already-raised", log.Fields{"onu-id": onuIPS.OnuId, "intf-id": onuIPS.IntfId})
663 } else {
664 if err := em.onuRemoteDefectIndication(onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
665 return err
666 }
667 onuDevice.(*OnuDevice).rdiRaised = false
668 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500669 return nil
670}
671
672func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
673 /* Populating event context */
674 context := map[string]string{
675 "onu-id": strconv.FormatUint(uint64(onuGCD.OnuId), base10),
676 "intf-id": strconv.FormatUint(uint64(onuGCD.IntfId), base10),
677 "delineation-errors": strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
678 }
679 /* Populating device event body */
680 de := &voltha.DeviceEvent{
681 Context: context,
682 ResourceId: deviceID,
683 }
684 if onuGCD.Status == statusCheckOn {
685 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
686 } else {
687 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
688 }
689 /* Send event to KAFKA */
690 if err := em.eventProxy.SendDeviceEvent(de, communication, onu, raisedTs); err != nil {
691 return err
692 }
Shrey Baid26912972020-04-16 21:02:31 +0530693 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 -0500694 return nil
695}
696
697func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
698 /* Populating event context */
699 context := map[string]string{
700 "onu-id": strconv.FormatUint(uint64(onuErr.OnuId), base10),
701 "intf-id": strconv.FormatUint(uint64(onuErr.IntfId), base10),
702 }
703 /* Populating device event body */
704 de := &voltha.DeviceEvent{
705 Context: context,
706 ResourceId: deviceID,
707 }
708 if onuErr.Status == statusCheckOn {
709 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
710 } else {
711 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
712 }
713 /* Send event to KAFKA */
714 if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil {
715 return err
716 }
Shrey Baid26912972020-04-16 21:02:31 +0530717 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 -0500718 return nil
719}
720
721func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
722 /* Populating event context */
723 context := map[string]string{
724 "onu-id": strconv.FormatUint(uint64(onuLOA.OnuId), base10),
725 "intf-id": strconv.FormatUint(uint64(onuLOA.IntfId), base10),
726 }
727 /* Populating device event body */
728 de := &voltha.DeviceEvent{
729 Context: context,
730 ResourceId: deviceID,
731 }
732 if onuLOA.Status == statusCheckOn {
733 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
734 } else {
735 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
736 }
737 /* Send event to KAFKA */
738 if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil {
739 return err
740 }
Shrey Baid26912972020-04-16 21:02:31 +0530741 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 -0500742 return nil
743}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400744
745func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
746 /* Populating event context */
747 context := map[string]string{
748 "onu-id": strconv.FormatUint(uint64(onuDRE.OnuId), base10),
749 "intf-id": strconv.FormatUint(uint64(onuDRE.IntfId), base10),
750 "differential-distance": strconv.FormatUint(uint64(onuDRE.Distance), base10),
751 }
752 /* Populating device event body */
753 de := &voltha.DeviceEvent{
754 Context: context,
755 ResourceId: deviceID,
756 }
757 if onuDRE.Status == statusCheckOn {
758 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
759 } else {
760 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
761 }
762 /* Send event to KAFKA */
763 if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil {
764 return err
765 }
Shrey Baid26912972020-04-16 21:02:31 +0530766 log.Debugw("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 -0400767 return nil
768}