blob: 835abe611c8beb70fb4fbdf801456d43103d7cdd [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)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400297 /* Populating device event body */
298 de.Context = context
299 de.ResourceId = deviceID
300 de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
301 /* Send event to KAFKA */
302 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
303 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 +0530304 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400305 }
306 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 +0530307 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400308}
309
Naga Manjunath9546b912019-11-28 20:56:20 +0530310func (em *OpenOltEventMgr) onuLossOmciIndication(onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400311 var de voltha.DeviceEvent
312 context := make(map[string]string)
313 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530314 context["intf-id"] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
315 context["onu-id"] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400316 /* Populating device event body */
317 de.Context = context
318 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530319 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400320 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
321 } else {
322 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
323 }
324 /* Send event to KAFKA */
325 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
326 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 +0530327 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400328 }
329 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 +0530330 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400331}
332
Naga Manjunath9546b912019-11-28 20:56:20 +0530333func (em *OpenOltEventMgr) onuDriftOfWindowIndication(onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400334 var de voltha.DeviceEvent
335 context := make(map[string]string)
336 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530337 context["intf-id"] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
338 context["onu-id"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
339 context["drift"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
340 context["new-eqd"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400341 /* Populating device event body */
342 de.Context = context
343 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530344 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400345 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
346 } else {
347 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
348 }
349 /* Send event to KAFKA */
350 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
351 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 +0530352 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400353 }
354 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 +0530355 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400356}
357
Naga Manjunath9546b912019-11-28 20:56:20 +0530358func (em *OpenOltEventMgr) onuSignalDegradeIndication(onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400359 var de voltha.DeviceEvent
360 context := make(map[string]string)
361 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530362 context["intf-id"] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
363 context["onu-id"] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400364 /* Populating device event body */
365 de.Context = context
366 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530367 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400368 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
369 } else {
370 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
371 }
372 /* Send event to KAFKA */
373 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
374 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 +0530375 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400376 }
377 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 +0530378 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400379}
380
Naga Manjunath9546b912019-11-28 20:56:20 +0530381func (em *OpenOltEventMgr) onuSignalsFailIndication(onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400382 var de voltha.DeviceEvent
383 context := make(map[string]string)
384 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530385 context["onu-id"] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
386 context["intf-id"] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
387 context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400388 /* Populating device event body */
389 de.Context = context
390 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530391 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400392 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
393 } else {
394 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
395 }
396 /* Send event to KAFKA */
397 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
398 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 +0530399 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400400 }
401 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 +0530402 return nil
403}
404
Naga Manjunathf6f74642020-01-13 21:37:28 +0530405func (em *OpenOltEventMgr) onuStartupFailedIndication(onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
406 var de voltha.DeviceEvent
407 context := make(map[string]string)
408 /* Populating event context */
409 context["onu-id"] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
410 context["intf-id"] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
411
412 /* Populating device event body */
413 de.Context = context
414 de.ResourceId = deviceID
415 if onuStartupFail.Status == statusCheckOn {
416 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
417 } else {
418 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
419 }
420 /* Send event to KAFKA */
421 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
422 log.Errorw("Failed to send ONU startup fail event", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId})
423 return err
424 }
425 log.Infow("ONU startup fail event sent to KAFKA", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId})
426 return nil
427}
428
Naga Manjunath9546b912019-11-28 20:56:20 +0530429func (em *OpenOltEventMgr) onuLossOfSyncIndication(onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
430 var de voltha.DeviceEvent
431 context := make(map[string]string)
432 /* Populating event context */
433 context["onu-id"] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
434 context["intf-id"] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
435 /* Populating device event body */
436 de.Context = context
437 de.ResourceId = deviceID
438 if onuLOKI.Status == statusCheckOn {
439 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
440 } else {
441 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
442 }
443
444 /* Send event to KAFKA */
445 if err := em.eventProxy.SendDeviceEvent(&de, security, onu, raisedTs); err != nil {
446 log.Errorw("Failed to send ONU loss of key sync event", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
447 return err
448 }
449 log.Infow("ONU loss of key sync event sent to KAFKA", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
450 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400451}
kesavand39e0aa32020-01-28 20:58:50 -0500452
453// oltIntfOperIndication handles Up and Down state of an OLT PON ports
454func (em *OpenOltEventMgr) oltIntfOperIndication(ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
455 var de voltha.DeviceEvent
456 context := make(map[string]string)
457 portID := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
458 device, err := em.handler.coreProxy.GetDevice(ctx.Background(), deviceID, deviceID)
459 if err != nil {
460 log.Errorw("Error while fetching Device object", log.Fields{"DeviceId": deviceID})
461 }
462 for _, port := range device.Ports {
463 if port.PortNo == portID {
464 // Events are suppressed if the Port Adminstate is not enabled.
465 if port.AdminState != common.AdminState_ENABLED {
466 log.Infow("Port disable/enable event not generated because, The port is not enabled by operator", log.Fields{"deviceId": deviceID, "port": port})
467 return
468 }
469 break
470 }
471 }
472 /* Populating event context */
473 context["oper-state"] = ifindication.GetOperState()
474 /* Populating device event body */
475 de.Context = context
476 de.ResourceId = deviceID
477
478 if ifindication.GetOperState() == operationStateDown {
479 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
480 } else if ifindication.OperState == operationStateUp {
481 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
482 }
483 /* Send event to KAFKA */
484 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
485 log.Errorw("failed-to-send-olt-intf-oper-status-event", log.Fields{"err": err})
486 }
487 log.Info("sent-olt-intf-oper-status-event-to-kafka")
488}