blob: 46178cc6d25a473261455ba61fbf4a659d28e825 [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 (
21 "fmt"
Naga Manjunath9546b912019-11-28 20:56:20 +053022 "strconv"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053023
Scott Baker51290152019-10-24 14:23:20 -070024 "github.com/opencord/voltha-lib-go/v2/pkg/adapters/adapterif"
25 "github.com/opencord/voltha-lib-go/v2/pkg/log"
Scott Bakerc6e54cb2019-11-04 09:31:25 -080026 oop "github.com/opencord/voltha-protos/v2/go/openolt"
27 "github.com/opencord/voltha-protos/v2/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040028)
29
30const (
31 onuDiscoveryEvent = "ONU_DISCOVERY"
32 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
33 onuLobEvent = "ONU_LOSS_OF_BURST"
34 onuLopcMissEvent = "ONU_LOPC_MISS"
35 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
36 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
Daniele Rossi051466a2019-07-26 13:39:37 +000037 oltIndicationDown = "OLT_DOWN_INDICATION"
Devmalya Paulfb990a52019-07-09 10:01:49 -040038 onuDyingGaspEvent = "ONU_DYING_GASP"
39 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
40 onuStartupFailEvent = "ONU_STARTUP_FAIL"
41 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
42 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
43 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
44 onuProcessingErrorEvent = "ONU_PROCESSING_ERROR"
45 onuTiwiEvent = "ONU_TRANSMISSION_WARNING"
46 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
Naga Manjunath9546b912019-11-28 20:56:20 +053047 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
48 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
Naga Manjunathffa5c212019-12-06 15:15:04 +053049 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
Devmalya Paulfb990a52019-07-09 10:01:49 -040050)
51
52const (
53 pon = voltha.EventSubCategory_PON
54 olt = voltha.EventSubCategory_OLT
55 ont = voltha.EventSubCategory_ONT
56 onu = voltha.EventSubCategory_ONU
57 nni = voltha.EventSubCategory_NNI
58 service = voltha.EventCategory_SERVICE
59 security = voltha.EventCategory_SECURITY
60 equipment = voltha.EventCategory_EQUIPMENT
61 processing = voltha.EventCategory_PROCESSING
62 environment = voltha.EventCategory_ENVIRONMENT
63 communication = voltha.EventCategory_COMMUNICATION
64)
65
Naga Manjunath9546b912019-11-28 20:56:20 +053066const (
67 // statusCheckOn represents status check On
68 statusCheckOn = "on"
69 // statusCheckOff represents status check Off
70 statusCheckOff = "off"
71 // operationStateUp represents operation state Up
72 operationStateUp = "up"
73 // operationStateDown represents operation state Down
74 operationStateDown = "down"
75 // base10 represents base 10 conversion
76 base10 = 10
77)
78
Devmalya Paulfb990a52019-07-09 10:01:49 -040079// OpenOltEventMgr struct contains
80type OpenOltEventMgr struct {
kdarapu381c6902019-07-31 18:23:16 +053081 eventProxy adapterif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040082 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -040083}
84
85// 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 -040086func NewEventMgr(eventProxy adapterif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -040087 var em OpenOltEventMgr
88 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040089 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -040090 return &em
91}
92
93// ProcessEvents is function to process and publish OpenOLT event
94func (em *OpenOltEventMgr) ProcessEvents(alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +053095 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -040096 switch alarmInd.Data.(type) {
97 case *oop.AlarmIndication_LosInd:
98 log.Infow("Received LOS indication", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +053099 err = em.oltLosIndication(alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400100
101 case *oop.AlarmIndication_OnuAlarmInd:
102 log.Infow("Received onu alarm indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530103 err = em.onuAlarmIndication(alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400104
105 case *oop.AlarmIndication_DyingGaspInd:
106 log.Infow("Received dying gasp indication", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530107 err = em.onuDyingGaspIndication(alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400108 case *oop.AlarmIndication_OnuActivationFailInd:
109 log.Infow("Received onu activation fail indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530110 err = em.onuActivationFailIndication(alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400111
112 case *oop.AlarmIndication_OnuLossOmciInd:
113 log.Infow("Received onu loss omci indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530114 err = em.onuLossOmciIndication(alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400115
116 case *oop.AlarmIndication_OnuDriftOfWindowInd:
117 log.Infow("Received onu drift of window indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530118 err = em.onuDriftOfWindowIndication(alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400119
120 case *oop.AlarmIndication_OnuSignalDegradeInd:
121 log.Infow("Received onu signal degrade indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530122 err = em.onuSignalDegradeIndication(alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400123
124 case *oop.AlarmIndication_OnuSignalsFailInd:
125 log.Infow("Received onu signal fail indication ", log.Fields{"alarm_ind": alarmInd})
Naga Manjunath9546b912019-11-28 20:56:20 +0530126 err = em.onuSignalsFailIndication(alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400127
128 case *oop.AlarmIndication_OnuProcessingErrorInd:
129 log.Infow("Received onu startup fail indication ", log.Fields{"alarm_ind": alarmInd})
130 log.Infow("Not implemented yet", log.Fields{"alarm_ind": alarmInd})
131 case *oop.AlarmIndication_OnuTiwiInd:
132 log.Infow("Received onu transmission warning indication ", log.Fields{"alarm_ind": alarmInd})
133 log.Infow("Not implemented yet", log.Fields{"alarm_ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530134 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
135 log.Infow("Received onu Loss of Sync Fail indication ", log.Fields{"alarm_ind": alarmInd})
136 err = em.onuLossOfSyncIndication(alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
137 case *oop.AlarmIndication_OnuItuPonStatsInd:
138 log.Infow("Received onu Itu Pon Stats indication ", log.Fields{"alarm_ind": alarmInd})
139 log.Infow("Not implemented yet", log.Fields{"alarm_ind": alarmInd})
Devmalya Paulfb990a52019-07-09 10:01:49 -0400140 default:
141 log.Errorw("Received unknown indication type", log.Fields{"alarm_ind": alarmInd})
142
143 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530144 if err != nil {
145 log.Errorw("Failed to publish message to KAFKA", log.Fields{"error": err})
146 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400147}
148
Daniele Rossi051466a2019-07-26 13:39:37 +0000149// oltUpDownIndication handles Up and Down state of an OLT
Naga Manjunath9546b912019-11-28 20:56:20 +0530150func (em *OpenOltEventMgr) oltUpDownIndication(oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000151 var de voltha.DeviceEvent
152 context := make(map[string]string)
153 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530154 context["oper-state"] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000155 /* Populating device event body */
156 de.Context = context
157 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530158 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000159 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530160 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000161 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
162 }
163 /* Send event to KAFKA */
164 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
165 log.Errorw("Failed to send OLT event", log.Fields{"err": err})
Naga Manjunath9546b912019-11-28 20:56:20 +0530166 return err
Daniele Rossi051466a2019-07-26 13:39:37 +0000167 }
168 log.Infow("OLT UpDown event sent to KAFKA", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530169 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000170}
171
Devmalya Paulfb990a52019-07-09 10:01:49 -0400172// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Naga Manjunath9546b912019-11-28 20:56:20 +0530173func (em *OpenOltEventMgr) OnuDiscoveryIndication(onuDisc *oop.OnuDiscIndication, deviceID string, OnuID uint32, serialNumber string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400174 var de voltha.DeviceEvent
175 context := make(map[string]string)
176 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530177 context["onu-id"] = strconv.FormatUint(uint64(OnuID), base10)
178 context["intf-id"] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400179 context["serial-number"] = serialNumber
180 /* Populating device event body */
181 de.Context = context
182 de.ResourceId = deviceID
183 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
184 /* Send event to KAFKA */
185 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
186 log.Errorw("Failed to send ONU discovery event", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530187 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400188 }
189 log.Infow("ONU discovery event sent to KAFKA", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530190 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400191}
192
Naga Manjunath9546b912019-11-28 20:56:20 +0530193func (em *OpenOltEventMgr) oltLosIndication(oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400194 var de voltha.DeviceEvent
195 context := make(map[string]string)
196 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530197 context["intf-id"] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400198 /* Populating device event body */
199 de.Context = context
200 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530201 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400202 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
203 } else {
204 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
205 }
206 /* Send event to KAFKA */
207 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
208 log.Errorw("Failed to send OLT loss of signal event", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530209 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400210 }
211 log.Infow("OLT LOS event sent to KAFKA", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530212 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400213}
214
Naga Manjunath9546b912019-11-28 20:56:20 +0530215func (em *OpenOltEventMgr) onuDyingGaspIndication(dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400216 var de voltha.DeviceEvent
Devmalya Paul90ca3012019-09-02 21:55:45 -0400217 var serialNumber string
Devmalya Paulfb990a52019-07-09 10:01:49 -0400218 context := make(map[string]string)
219 /* Populating event context */
Devmalya Paul90ca3012019-09-02 21:55:45 -0400220 serialNumber = ""
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530221 onu := em.handler.formOnuKey(dgi.IntfId, dgi.OnuId)
222 if onu, ok := em.handler.onus.Load(onu); ok {
223 serialNumber = onu.(*OnuDevice).serialNumber
Devmalya Paul90ca3012019-09-02 21:55:45 -0400224 }
225 context["serial-number"] = serialNumber
Naga Manjunath9546b912019-11-28 20:56:20 +0530226 context["intf-id"] = strconv.FormatUint(uint64(dgi.IntfId), base10)
227 context["onu-id"] = strconv.FormatUint(uint64(dgi.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400228 /* Populating device event body */
229 de.Context = context
230 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530231 if dgi.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400232 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "RAISE_EVENT")
233 } else {
234 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "CLEAR_EVENT")
235 }
236 /* Send event to KAFKA */
237 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
238 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 +0530239 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400240 }
241 log.Infow("ONU dying gasp event sent to KAFKA", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530242 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400243}
244
Naga Manjunath9546b912019-11-28 20:56:20 +0530245func (em *OpenOltEventMgr) onuAlarmIndication(onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400246 var de voltha.DeviceEvent
247 context := make(map[string]string)
248 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530249 context["intf-id"] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
250 context["onu-id"] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400251 /* Populating device event body */
252 de.Context = context
253 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530254 if onuAlarm.LosStatus == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400255 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530256 } else if onuAlarm.LosStatus == statusCheckOff {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400257 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530258 } else if onuAlarm.LobStatus == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400259 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530260 } else if onuAlarm.LobStatus == statusCheckOff {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400261 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530262 } else if onuAlarm.LopcMissStatus == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400263 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530264 } else if onuAlarm.LopcMissStatus == statusCheckOff {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400265 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530266 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400267 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530268 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400269 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530270 } else if onuAlarm.LofiStatus == statusCheckOn {
271 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
272 } else if onuAlarm.LofiStatus == statusCheckOff {
273 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
Naga Manjunathffa5c212019-12-06 15:15:04 +0530274 } else if onuAlarm.LoamiStatus == statusCheckOn {
275 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
276 } else if onuAlarm.LoamiStatus == statusCheckOff {
277 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400278 }
279 /* Send event to KAFKA */
280 if err := em.eventProxy.SendDeviceEvent(&de, communication, onu, raisedTs); err != nil {
281 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 +0530282 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400283 }
284 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 +0530285 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400286}
287
Naga Manjunath9546b912019-11-28 20:56:20 +0530288func (em *OpenOltEventMgr) onuActivationFailIndication(oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400289 var de voltha.DeviceEvent
290 context := make(map[string]string)
291 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530292 context["intf-id"] = strconv.FormatUint(uint64(oaf.IntfId), base10)
293 context["onu-id"] = strconv.FormatUint(uint64(oaf.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400294 /* Populating device event body */
295 de.Context = context
296 de.ResourceId = deviceID
297 de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
298 /* Send event to KAFKA */
299 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
300 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 +0530301 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400302 }
303 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 +0530304 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400305}
306
Naga Manjunath9546b912019-11-28 20:56:20 +0530307func (em *OpenOltEventMgr) onuLossOmciIndication(onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400308 var de voltha.DeviceEvent
309 context := make(map[string]string)
310 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530311 context["intf-id"] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
312 context["onu-id"] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400313 /* Populating device event body */
314 de.Context = context
315 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530316 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400317 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
318 } else {
319 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
320 }
321 /* Send event to KAFKA */
322 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
323 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 +0530324 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400325 }
326 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 +0530327 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400328}
329
Naga Manjunath9546b912019-11-28 20:56:20 +0530330func (em *OpenOltEventMgr) onuDriftOfWindowIndication(onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400331 var de voltha.DeviceEvent
332 context := make(map[string]string)
333 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530334 context["intf-id"] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
335 context["onu-id"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
336 context["drift"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
337 context["new-eqd"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400338 /* Populating device event body */
339 de.Context = context
340 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530341 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400342 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
343 } else {
344 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
345 }
346 /* Send event to KAFKA */
347 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
348 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 +0530349 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400350 }
351 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 +0530352 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400353}
354
Naga Manjunath9546b912019-11-28 20:56:20 +0530355func (em *OpenOltEventMgr) onuSignalDegradeIndication(onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400356 var de voltha.DeviceEvent
357 context := make(map[string]string)
358 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530359 context["intf-id"] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
360 context["onu-id"] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400361 /* Populating device event body */
362 de.Context = context
363 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530364 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400365 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
366 } else {
367 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
368 }
369 /* Send event to KAFKA */
370 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
371 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 +0530372 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400373 }
374 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 +0530375 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400376}
377
Naga Manjunath9546b912019-11-28 20:56:20 +0530378func (em *OpenOltEventMgr) onuSignalsFailIndication(onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400379 var de voltha.DeviceEvent
380 context := make(map[string]string)
381 /* Populating event context */
Naga Manjunath9546b912019-11-28 20:56:20 +0530382 context["onu-id"] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
383 context["intf-id"] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
384 context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400385 /* Populating device event body */
386 de.Context = context
387 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530388 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400389 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
390 } else {
391 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
392 }
393 /* Send event to KAFKA */
394 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
395 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 +0530396 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400397 }
398 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 +0530399 return nil
400}
401
402func (em *OpenOltEventMgr) onuLossOfSyncIndication(onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
403 var de voltha.DeviceEvent
404 context := make(map[string]string)
405 /* Populating event context */
406 context["onu-id"] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
407 context["intf-id"] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
408 /* Populating device event body */
409 de.Context = context
410 de.ResourceId = deviceID
411 if onuLOKI.Status == statusCheckOn {
412 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
413 } else {
414 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
415 }
416
417 /* Send event to KAFKA */
418 if err := em.eventProxy.SendDeviceEvent(&de, security, onu, raisedTs); err != nil {
419 log.Errorw("Failed to send ONU loss of key sync event", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
420 return err
421 }
422 log.Infow("ONU loss of key sync event sent to KAFKA", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
423 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400424}