blob: 4205797b4482be4c4ff337624e20ad849c5fdde6 [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
17// Package adaptercore provides APIs for the openOLT adapter
18package adaptercore
19
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"
kesavand39e0aa32020-01-28 20:58:50 -050027 "github.com/opencord/voltha-protos/v3/go/common"
Esin Karamanccb714b2019-11-29 15:02:06 +000028 oop "github.com/opencord/voltha-protos/v3/go/openolt"
29 "github.com/opencord/voltha-protos/v3/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040030)
31
32const (
33 onuDiscoveryEvent = "ONU_DISCOVERY"
34 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
35 onuLobEvent = "ONU_LOSS_OF_BURST"
36 onuLopcMissEvent = "ONU_LOPC_MISS"
37 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
38 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
Daniele Rossi051466a2019-07-26 13:39:37 +000039 oltIndicationDown = "OLT_DOWN_INDICATION"
Devmalya Paulfb990a52019-07-09 10:01:49 -040040 onuDyingGaspEvent = "ONU_DYING_GASP"
41 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
42 onuStartupFailEvent = "ONU_STARTUP_FAIL"
43 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
44 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
45 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
46 onuProcessingErrorEvent = "ONU_PROCESSING_ERROR"
47 onuTiwiEvent = "ONU_TRANSMISSION_WARNING"
48 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
Naga Manjunath9546b912019-11-28 20:56:20 +053049 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
50 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
Naga Manjunathffa5c212019-12-06 15:15:04 +053051 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
kesavand39e0aa32020-01-28 20:58:50 -050052 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
Devmalya Paulfb990a52019-07-09 10:01:49 -040053)
54
55const (
56 pon = voltha.EventSubCategory_PON
57 olt = voltha.EventSubCategory_OLT
58 ont = voltha.EventSubCategory_ONT
59 onu = voltha.EventSubCategory_ONU
60 nni = voltha.EventSubCategory_NNI
61 service = voltha.EventCategory_SERVICE
62 security = voltha.EventCategory_SECURITY
63 equipment = voltha.EventCategory_EQUIPMENT
64 processing = voltha.EventCategory_PROCESSING
65 environment = voltha.EventCategory_ENVIRONMENT
66 communication = voltha.EventCategory_COMMUNICATION
67)
68
Naga Manjunath9546b912019-11-28 20:56:20 +053069const (
70 // statusCheckOn represents status check On
71 statusCheckOn = "on"
72 // statusCheckOff represents status check Off
73 statusCheckOff = "off"
74 // operationStateUp represents operation state Up
75 operationStateUp = "up"
76 // operationStateDown represents operation state Down
77 operationStateDown = "down"
78 // base10 represents base 10 conversion
79 base10 = 10
80)
81
Devmalya Paulfb990a52019-07-09 10:01:49 -040082// OpenOltEventMgr struct contains
83type OpenOltEventMgr struct {
kdarapu381c6902019-07-31 18:23:16 +053084 eventProxy adapterif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040085 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -040086}
87
88// 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 -040089func NewEventMgr(eventProxy adapterif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -040090 var em OpenOltEventMgr
91 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040092 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -040093 return &em
94}
95
96// ProcessEvents is function to process and publish OpenOLT event
97func (em *OpenOltEventMgr) ProcessEvents(alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +053098 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -040099 switch alarmInd.Data.(type) {
100 case *oop.AlarmIndication_LosInd:
101 log.Infow("Received LOS indication", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530102 err = em.oltLosIndication(alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400103
104 case *oop.AlarmIndication_OnuAlarmInd:
105 log.Infow("Received onu alarm indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530106 err = em.onuAlarmIndication(alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400107
108 case *oop.AlarmIndication_DyingGaspInd:
109 log.Infow("Received dying gasp indication", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530110 err = em.onuDyingGaspIndication(alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400111 case *oop.AlarmIndication_OnuActivationFailInd:
112 log.Infow("Received onu activation fail indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530113 err = em.onuActivationFailIndication(alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400114
115 case *oop.AlarmIndication_OnuLossOmciInd:
116 log.Infow("Received onu loss omci indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530117 err = em.onuLossOmciIndication(alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400118
119 case *oop.AlarmIndication_OnuDriftOfWindowInd:
120 log.Infow("Received onu drift of window indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530121 err = em.onuDriftOfWindowIndication(alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400122
123 case *oop.AlarmIndication_OnuSignalDegradeInd:
124 log.Infow("Received onu signal degrade indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530125 err = em.onuSignalDegradeIndication(alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400126
127 case *oop.AlarmIndication_OnuSignalsFailInd:
128 log.Infow("Received onu signal fail indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530129 err = em.onuSignalsFailIndication(alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400130
Naga Manjunathf6f74642020-01-13 21:37:28 +0530131 case *oop.AlarmIndication_OnuStartupFailInd:
Devmalya Paulfb990a52019-07-09 10:01:49 -0400132 log.Infow("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:
135 log.Infow("Received onu transmission warning indication ", log.Fields{"alarm_ind": alarmInd})
136 log.Infow("Not implemented yet", log.Fields{"alarm_ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530137 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
138 log.Infow("Received onu Loss of Sync Fail indication ", log.Fields{"alarm_ind": alarmInd})
139 err = em.onuLossOfSyncIndication(alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
140 case *oop.AlarmIndication_OnuItuPonStatsInd:
141 log.Infow("Received onu Itu Pon Stats indication ", log.Fields{"alarm_ind": alarmInd})
142 log.Infow("Not implemented yet", log.Fields{"alarm_ind": alarmInd})
Devmalya Paulfb990a52019-07-09 10:01:49 -0400143 default:
144 log.Errorw("Received unknown indication type", log.Fields{"alarm_ind": alarmInd})
145
146 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530147 if err != nil {
148 log.Errorw("Failed to publish message to KAFKA", log.Fields{"error": err})
149 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400150}
151
Daniele Rossi051466a2019-07-26 13:39:37 +0000152// oltUpDownIndication handles Up and Down state of an OLT
Naga Manjunath9546b912019-11-28 20:56:20 +0530153func (em *OpenOltEventMgr) oltUpDownIndication(oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000154 var de voltha.DeviceEvent
155 context := make(map[string]string)
156 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530157 context["oper-state"] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000158 /* Populating device event body */
159 de.Context = context
160 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530161 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000162 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530163 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000164 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
165 }
166 /* Send event to KAFKA */
167 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
168 log.Errorw("Failed to send OLT event", log.Fields{"err": err})
Naga Manjunath9546b912019-11-28 20:56:20 +0530169 return err
Daniele Rossi051466a2019-07-26 13:39:37 +0000170 }
171 log.Infow("OLT UpDown event sent to KAFKA", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530172 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000173}
174
Devmalya Paulfb990a52019-07-09 10:01:49 -0400175// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Naga Manjunath9546b912019-11-28 20:56:20 +0530176func (em *OpenOltEventMgr) OnuDiscoveryIndication(onuDisc *oop.OnuDiscIndication, deviceID string, OnuID uint32, serialNumber string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400177 var de voltha.DeviceEvent
178 context := make(map[string]string)
179 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530180 context["onu-id"] = strconv.FormatUint(uint64(OnuID), base10)
181 context["intf-id"] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400182 context["serial-number"] = serialNumber
183 /* Populating device event body */
184 de.Context = context
185 de.ResourceId = deviceID
186 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
187 /* Send event to KAFKA */
188 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
189 log.Errorw("Failed to send ONU discovery event", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530190 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400191 }
192 log.Infow("ONU discovery event sent to KAFKA", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530193 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400194}
195
Naga Manjunath9546b912019-11-28 20:56:20 +0530196func (em *OpenOltEventMgr) oltLosIndication(oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400197 var de voltha.DeviceEvent
198 context := make(map[string]string)
199 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530200 context["intf-id"] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400201 /* Populating device event body */
202 de.Context = context
203 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530204 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400205 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
206 } else {
207 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
208 }
209 /* Send event to KAFKA */
210 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
211 log.Errorw("Failed to send OLT loss of signal event", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530212 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400213 }
214 log.Infow("OLT LOS event sent to KAFKA", log.Fields{"intf-id": oltLos.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) onuDyingGaspIndication(dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400219 var de voltha.DeviceEvent
Devmalya Paul90ca3012019-09-02 21:55:45 -0400220 var serialNumber string
Devmalya Paulfb990a52019-07-09 10:01:49 -0400221 context := make(map[string]string)
222 /* Populating event context */
Devmalya Paul90ca3012019-09-02 21:55:45 -0400223 serialNumber = ""
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530224 onu := em.handler.formOnuKey(dgi.IntfId, dgi.OnuId)
225 if onu, ok := em.handler.onus.Load(onu); ok {
226 serialNumber = onu.(*OnuDevice).serialNumber
Devmalya Paul90ca3012019-09-02 21:55:45 -0400227 }
228 context["serial-number"] = serialNumber
Naga Manjunath9546b912019-11-28 20:56:20 +0530229 context["intf-id"] = strconv.FormatUint(uint64(dgi.IntfId), base10)
230 context["onu-id"] = strconv.FormatUint(uint64(dgi.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400231 /* Populating device event body */
232 de.Context = context
233 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530234 if dgi.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400235 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "RAISE_EVENT")
236 } else {
237 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "CLEAR_EVENT")
238 }
239 /* Send event to KAFKA */
240 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
241 log.Errorw("Failed to send ONU Dying gasp event", log.Fields{"intf-id": dgi.IntfId, "onu-id": dgi.OnuId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530242 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400243 }
244 log.Infow("ONU dying gasp event sent to KAFKA", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530245 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400246}
247
Naga Manjunath9546b912019-11-28 20:56:20 +0530248func (em *OpenOltEventMgr) onuAlarmIndication(onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400249 var de voltha.DeviceEvent
250 context := make(map[string]string)
251 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530252 context["intf-id"] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
253 context["onu-id"] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400254 /* Populating device event body */
255 de.Context = context
256 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530257 if onuAlarm.LosStatus == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400258 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530259 } else if onuAlarm.LosStatus == statusCheckOff {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400260 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530261 } else if onuAlarm.LobStatus == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400262 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530263 } else if onuAlarm.LobStatus == statusCheckOff {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400264 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530265 } else if onuAlarm.LopcMissStatus == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400266 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530267 } else if onuAlarm.LopcMissStatus == statusCheckOff {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400268 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530269 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400270 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530271 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400272 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530273 } else if onuAlarm.LofiStatus == statusCheckOn {
274 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
275 } else if onuAlarm.LofiStatus == statusCheckOff {
276 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
Naga Manjunathffa5c212019-12-06 15:15:04 +0530277 } else if onuAlarm.LoamiStatus == statusCheckOn {
278 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
279 } else if onuAlarm.LoamiStatus == statusCheckOff {
280 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400281 }
282 /* Send event to KAFKA */
283 if err := em.eventProxy.SendDeviceEvent(&de, communication, onu, raisedTs); err != nil {
284 log.Errorw("Failed to send ONU Los event", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530285 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400286 }
287 log.Infow("ONU LOS event sent to KAFKA", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530288 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400289}
290
Naga Manjunath9546b912019-11-28 20:56:20 +0530291func (em *OpenOltEventMgr) onuActivationFailIndication(oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400292 var de voltha.DeviceEvent
293 context := make(map[string]string)
294 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530295 context["intf-id"] = strconv.FormatUint(uint64(oaf.IntfId), base10)
296 context["onu-id"] = strconv.FormatUint(uint64(oaf.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800297 context["fail-reason"] = strconv.FormatUint(uint64(oaf.FailReason), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400298 /* Populating device event body */
299 de.Context = context
300 de.ResourceId = deviceID
301 de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
302 /* Send event to KAFKA */
303 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
304 log.Errorw("Failed to send ONU activation failure event", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530305 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400306 }
307 log.Infow("ONU activation failure event sent to KAFKA", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530308 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400309}
310
Naga Manjunath9546b912019-11-28 20:56:20 +0530311func (em *OpenOltEventMgr) onuLossOmciIndication(onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400312 var de voltha.DeviceEvent
313 context := make(map[string]string)
314 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530315 context["intf-id"] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
316 context["onu-id"] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400317 /* Populating device event body */
318 de.Context = context
319 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530320 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400321 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
322 } else {
323 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
324 }
325 /* Send event to KAFKA */
326 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
327 log.Errorw("Failed to send ONU loss of OMCI channel event", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530328 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400329 }
330 log.Infow("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 +0530331 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400332}
333
Naga Manjunath9546b912019-11-28 20:56:20 +0530334func (em *OpenOltEventMgr) onuDriftOfWindowIndication(onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400335 var de voltha.DeviceEvent
336 context := make(map[string]string)
337 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530338 context["intf-id"] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
339 context["onu-id"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800340 context["drift"] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
341 context["new-eqd"] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400342 /* Populating device event body */
343 de.Context = context
344 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530345 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400346 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
347 } else {
348 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
349 }
350 /* Send event to KAFKA */
351 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
352 log.Errorw("Failed to send ONU drift of window event", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530353 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400354 }
355 log.Infow("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 +0530356 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400357}
358
Naga Manjunath9546b912019-11-28 20:56:20 +0530359func (em *OpenOltEventMgr) onuSignalDegradeIndication(onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400360 var de voltha.DeviceEvent
361 context := make(map[string]string)
362 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530363 context["intf-id"] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
364 context["onu-id"] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
Scott Bakerd4df1182020-02-05 11:38:42 -0800365 context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400366 /* Populating device event body */
367 de.Context = context
368 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530369 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400370 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
371 } else {
372 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
373 }
374 /* Send event to KAFKA */
375 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
376 log.Errorw("Failed to send ONU signals degrade event", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530377 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400378 }
379 log.Infow("ONU signal degrade event sent to KAFKA", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530380 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400381}
382
Naga Manjunath9546b912019-11-28 20:56:20 +0530383func (em *OpenOltEventMgr) onuSignalsFailIndication(onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400384 var de voltha.DeviceEvent
385 context := make(map[string]string)
386 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530387 context["onu-id"] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
388 context["intf-id"] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
389 context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400390 /* Populating device event body */
391 de.Context = context
392 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530393 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400394 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
395 } else {
396 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
397 }
398 /* Send event to KAFKA */
399 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
400 log.Errorw("Failed to send ONU signals fail event", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530401 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400402 }
403 log.Infow("ONU signals fail event sent to KAFKA", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530404 return nil
405}
406
Naga Manjunathf6f74642020-01-13 21:37:28 +0530407func (em *OpenOltEventMgr) onuStartupFailedIndication(onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
408 var de voltha.DeviceEvent
409 context := make(map[string]string)
410 /* Populating event context */
411 context["onu-id"] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
412 context["intf-id"] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
413
414 /* Populating device event body */
415 de.Context = context
416 de.ResourceId = deviceID
417 if onuStartupFail.Status == statusCheckOn {
418 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
419 } else {
420 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
421 }
422 /* Send event to KAFKA */
423 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
424 log.Errorw("Failed to send ONU startup fail event", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId})
425 return err
426 }
427 log.Infow("ONU startup fail event sent to KAFKA", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId})
428 return nil
429}
430
Naga Manjunath9546b912019-11-28 20:56:20 +0530431func (em *OpenOltEventMgr) onuLossOfSyncIndication(onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
432 var de voltha.DeviceEvent
433 context := make(map[string]string)
434 /* Populating event context */
435 context["onu-id"] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
436 context["intf-id"] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
437 /* Populating device event body */
438 de.Context = context
439 de.ResourceId = deviceID
440 if onuLOKI.Status == statusCheckOn {
441 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
442 } else {
443 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
444 }
445
446 /* Send event to KAFKA */
447 if err := em.eventProxy.SendDeviceEvent(&de, security, onu, raisedTs); err != nil {
448 log.Errorw("Failed to send ONU loss of key sync event", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
449 return err
450 }
451 log.Infow("ONU loss of key sync event sent to KAFKA", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
452 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400453}
kesavand39e0aa32020-01-28 20:58:50 -0500454
455// oltIntfOperIndication handles Up and Down state of an OLT PON ports
456func (em *OpenOltEventMgr) oltIntfOperIndication(ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
457 var de voltha.DeviceEvent
458 context := make(map[string]string)
459 portID := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
460 device, err := em.handler.coreProxy.GetDevice(ctx.Background(), deviceID, deviceID)
461 if err != nil {
462 log.Errorw("Error while fetching Device object", log.Fields{"DeviceId": deviceID})
463 }
464 for _, port := range device.Ports {
465 if port.PortNo == portID {
466 // Events are suppressed if the Port Adminstate is not enabled.
467 if port.AdminState != common.AdminState_ENABLED {
468 log.Infow("Port disable/enable event not generated because, The port is not enabled by operator", log.Fields{"deviceId": deviceID, "port": port})
469 return
470 }
471 break
472 }
473 }
474 /* Populating event context */
475 context["oper-state"] = ifindication.GetOperState()
476 /* Populating device event body */
477 de.Context = context
478 de.ResourceId = deviceID
479
480 if ifindication.GetOperState() == operationStateDown {
481 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
482 } else if ifindication.OperState == operationStateUp {
483 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
484 }
485 /* Send event to KAFKA */
486 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
487 log.Errorw("failed-to-send-olt-intf-oper-status-event", log.Fields{"err": err})
488 }
489 log.Info("sent-olt-intf-oper-status-event-to-kafka")
490}