blob: f62f8a8f89e94e8de95f9a3c551d5aeadbbe4a3a [file] [log] [blame]
Takahiro Suzukid7bf8202020-12-17 20:21:59 +09001/*
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 core provides APIs for the openOLT adapter
18package core
19
20import (
21 "context"
22 "errors"
23 "fmt"
24 "strconv"
25
26 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
27 "github.com/opencord/voltha-lib-go/v3/pkg/log"
28 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
29 "github.com/opencord/voltha-protos/v3/go/common"
30 oop "github.com/opencord/voltha-protos/v3/go/openolt"
31 "github.com/opencord/voltha-protos/v3/go/voltha"
32)
33
34const (
35 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 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
49 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
50 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
51 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
52 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
53 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
54 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
55 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
56 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
57 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
58 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
59)
60
61const (
62 statusCheckOn = "on"
63 statusCheckOff = "off"
64 operationStateUp = "up"
65 operationStateDown = "down"
66 base10 = 10
67)
68
69const (
70 ContextOltOperState = "oper-state"
71 ContextOnuOnuID = "onu-id"
72 ContextOnuPonIntfID = "intf-id"
73 ContextOnuSerialNumber = "serial-number"
74 ContextOnuDeviceID = "onu-device-id"
75 ContextOltPonIntfID = "intf-id"
76 ContextOnuFailureReaseon = "fail-reason"
77 ContextOnuDrift = "drift"
78 ContextOnuNewEqd = "new-eqd"
79 ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
80 ContextOltPonIntfOperState = "oper-state"
81 ContextOnuRemoteDefectIndicatorCount = "rdi-count"
82 ContextOnuDelineationErrors = "delineation-errors"
83 ContextOnuDifferentialDistance = "differential-distance"
84)
85
86// OpenOltEventMgr struct contains
87type OpenOltEventMgr struct {
88 eventProxy adapterif.EventProxy
89 handler *DeviceHandler
90}
91
92// NewEventMgr is a Function to get a new event manager struct for the OpenOLT to process and publish OpenOLT event
93func NewEventMgr(eventProxy adapterif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
94 var em OpenOltEventMgr
95 em.eventProxy = eventProxy
96 em.handler = handler
97 return &em
98}
99
100// ProcessEvents is function to process and publish OpenOLT event
101// nolint: gocyclo
102func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
103 var err error
104 switch alarmInd.Data.(type) {
105 case *oop.AlarmIndication_LosInd:
106 logger.Debugw(ctx, "received-los-indication", log.Fields{"alarm-ind": alarmInd})
107 err = em.oltLosIndication(ctx, alarmInd.GetLosInd(), deviceID, raisedTs)
108 case *oop.AlarmIndication_OnuAlarmInd:
109 logger.Debugw(ctx, "received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
110 err = em.onuAlarmIndication(ctx, alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
111 case *oop.AlarmIndication_DyingGaspInd:
112 logger.Debugw(ctx, "received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
113 err = em.onuDyingGaspIndication(ctx, alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
114 case *oop.AlarmIndication_OnuActivationFailInd:
115 logger.Debugw(ctx, "received-onu-activation-fail-indication ", log.Fields{"alarm-ind": alarmInd})
116 err = em.onuActivationFailIndication(ctx, alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs)
117 case *oop.AlarmIndication_OnuLossOmciInd:
118 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
119 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
120 case *oop.AlarmIndication_OnuDriftOfWindowInd:
121 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
122 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
123 case *oop.AlarmIndication_OnuSignalDegradeInd:
124 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
125 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
126 case *oop.AlarmIndication_OnuSignalsFailInd:
127 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
128 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
129 case *oop.AlarmIndication_OnuStartupFailInd:
130 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
131 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
132 case *oop.AlarmIndication_OnuTiwiInd:
133 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
134 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
135 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
136 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
137 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
138 case *oop.AlarmIndication_OnuItuPonStatsInd:
139 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
140 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
141 case *oop.AlarmIndication_OnuDeactivationFailureInd:
142 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
143 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
144 case *oop.AlarmIndication_OnuLossGemDelineationInd:
145 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
146 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
147 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
148 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
149 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
150 case *oop.AlarmIndication_OnuLossOfAckInd:
151 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
152 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
153 case *oop.AlarmIndication_OnuDiffReachExceededInd:
154 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
155 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
156 default:
157 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
158 }
159 if err != nil {
160 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
161 }
162}
163
164// oltUpDownIndication handles Up and Down state of an OLT
165func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
166 var de voltha.DeviceEvent
167 context := make(map[string]string)
168 /* Populating event context */
169 context[ContextOltOperState] = oltIndication.OperState
170 /* Populating device event body */
171 de.Context = context
172 de.ResourceId = deviceID
173 if oltIndication.OperState == operationStateDown {
174 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
175 } else if oltIndication.OperState == operationStateUp {
176 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
177 }
178 /* Send event to KAFKA */
179 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
180 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
181 }
182 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
183 return nil
184}
185
186// OnuDiscoveryIndication is an exported method to handle ONU discovery event
187func (em *OpenOltEventMgr) OnuDiscoveryIndication(ctx context.Context, onuDisc *oop.OnuDiscIndication, oltDeviceID string, onuDeviceID string, OnuID uint32, serialNumber string, raisedTs int64) error {
188 var de voltha.DeviceEvent
189 context := make(map[string]string)
190 /* Populating event context */
191 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
192 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
193 context[ContextOnuSerialNumber] = serialNumber
194 context[ContextOnuDeviceID] = onuDeviceID
195 /* Populating device event body */
196 de.Context = context
197 de.ResourceId = oltDeviceID
198 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
199 /* Send event to KAFKA */
200 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
201 return olterrors.NewErrCommunication("send-onu-discovery-event",
202 log.Fields{
203 "serial-number": serialNumber,
204 "intf-id": onuDisc.IntfId}, err)
205 }
206 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
207 log.Fields{
208 "serial-number": serialNumber,
209 "intf-id": onuDisc.IntfId})
210 return nil
211}
212
213func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
214 var err error = nil
215 var de voltha.DeviceEvent
216 var alarmInd oop.OnuAlarmIndication
217 ponIntdID := PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
218
219 context := make(map[string]string)
220 /* Populating event context */
221 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
222 /* Populating device event body */
223 de.Context = context
224 de.ResourceId = deviceID
225 if oltLos.Status == statusCheckOn {
226 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
227
228 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
229 with "los_status: on" should be raised for each Onu connected to the PON
230 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
231 for all the ONU's connected to PON on receiving LoSIndication for PON */
232 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
233 if onuInCache.(*OnuDevice).intfID == ponIntdID {
234 alarmInd.IntfId = ponIntdID
235 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
236 alarmInd.LosStatus = statusCheckOn
237 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
238 }
239 return true
240 })
241 if err != nil {
242 /* Return if any error encountered while processing ONU LoS Event*/
243 return err
244 }
245 } else {
246 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
247 }
248 /* Send event to KAFKA */
249 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
250 return err
251 }
252 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": oltLos.IntfId})
253 return nil
254}
255
256func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) {
257 var serialNumber = ""
258 var onuDeviceID = ""
259 onu := em.handler.formOnuKey(intfID, onuID)
260 if onu, ok := em.handler.onus.Load(onu); ok {
261 serialNumber = onu.(*OnuDevice).serialNumber
262 onuDeviceID = onu.(*OnuDevice).deviceID
263 }
264
265 context[ContextOnuSerialNumber] = serialNumber
266 context[ContextOnuDeviceID] = onuDeviceID
267}
268
269func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
270 var de voltha.DeviceEvent
271 context := make(map[string]string)
272 /* Populating event context */
273 em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
274
275 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
276 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
277
278 /* Populating device event body */
279 de.Context = context
280 de.ResourceId = deviceID
281 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
282 /* Send event to KAFKA */
283 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
284 return err
285 }
286 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
287 return nil
288}
289
290//wasLosRaised checks whether los raised already. If already raised returns true else false
291func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
292 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
293 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
294 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
295
296 if onuAlarm.LosStatus == statusCheckOn {
297 if onuInCache.(*OnuDevice).losRaised {
298 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
299 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
300 return true
301 }
302 return false
303 }
304 }
305 return true
306}
307
308//wasLosCleared checks whether los cleared already. If already cleared returns true else false
309func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
310 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
311 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
312 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
313
314 if onuAlarm.LosStatus == statusCheckOff {
315 if !onuInCache.(*OnuDevice).losRaised {
316 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
317 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
318 return true
319 }
320 return false
321 }
322 }
323 return true
324}
325
326func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
327 var deviceEventName string
328 if onuAlarm.LosStatus == statusCheckOn {
329 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
330 } else if onuAlarm.LosStatus == statusCheckOff {
331 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
332 } else if onuAlarm.LobStatus == statusCheckOn {
333 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
334 } else if onuAlarm.LobStatus == statusCheckOff {
335 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
336 } else if onuAlarm.LopcMissStatus == statusCheckOn {
337 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
338 } else if onuAlarm.LopcMissStatus == statusCheckOff {
339 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
340 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
341 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
342 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
343 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
344 } else if onuAlarm.LofiStatus == statusCheckOn {
345 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
346 } else if onuAlarm.LofiStatus == statusCheckOff {
347 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
348 } else if onuAlarm.LoamiStatus == statusCheckOn {
349 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
350 } else if onuAlarm.LoamiStatus == statusCheckOff {
351 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
352 }
353 return deviceEventName
354}
355
356func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
357 var de voltha.DeviceEvent
358
359 context := make(map[string]string)
360 /* Populating event context */
361 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
362 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
363 em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
364
365 /* Populating device event body */
366 de.Context = context
367 de.ResourceId = deviceID
368 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
369
370 switch onuAlarm.LosStatus {
371 case statusCheckOn:
372 if em.wasLosRaised(ctx, onuAlarm) {
373 /* No need to raise Onu Los Event as it might have already raised
374 or Onu might have deleted */
375 return nil
376 }
377 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
378 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
379 /* Update onu device with LoS raised state as true */
380 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
381 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
382 onuInCache.(*OnuDevice).proxyDeviceID, true))
383 }
384 case statusCheckOff:
385 if em.wasLosCleared(ctx, onuAlarm) {
386 /* No need to clear Onu Los Event as it might have already cleared
387 or Onu might have deleted */
388 return nil
389 }
390 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
391 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
392 /* Update onu device with LoS raised state as false */
393 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
394 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
395 onuInCache.(*OnuDevice).proxyDeviceID, false))
396 }
397 }
398
399 /* Send event to KAFKA */
400 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
401 return err
402 }
403 logger.Debugw(ctx, "onu-los-event-sent-to-kafka", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId})
404 return nil
405}
406
407func (em *OpenOltEventMgr) onuActivationFailIndication(ctx context.Context, oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) error {
408 var de voltha.DeviceEvent
409 context := make(map[string]string)
410 /* Populating event context */
411 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(oaf.IntfId), base10)
412 context[ContextOnuOnuID] = strconv.FormatUint(uint64(oaf.OnuId), base10)
413 context[ContextOnuFailureReaseon] = strconv.FormatUint(uint64(oaf.FailReason), base10)
414
415 em.populateContextWithSerialDeviceID(context, oaf.IntfId, oaf.OnuId)
416
417 /* Populating device event body */
418 de.Context = context
419 de.ResourceId = deviceID
420 de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
421 /* Send event to KAFKA */
422 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
423 return err
424 }
425 logger.Debugw(ctx, "onu-activation-failure-event-sent-to-kafka", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId})
426 return nil
427}
428
429func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
430 var de voltha.DeviceEvent
431 context := make(map[string]string)
432 /* Populating event context */
433 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
434 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
435
436 em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
437
438 /* Populating device event body */
439 de.Context = context
440 de.ResourceId = deviceID
441 if onuLossOmci.Status == statusCheckOn {
442 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
443 } else {
444 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
445 }
446 /* Send event to KAFKA */
447 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
448 return err
449 }
450 logger.Debugw(ctx, "onu-loss-of-omci-channel-event-sent-to-kafka", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId})
451 return nil
452}
453
454func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
455 var de voltha.DeviceEvent
456 context := make(map[string]string)
457 /* Populating event context */
458 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
459 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
460 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
461 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
462
463 em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
464
465 /* Populating device event body */
466 de.Context = context
467 de.ResourceId = deviceID
468 if onuDriftWindow.Status == statusCheckOn {
469 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
470 } else {
471 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
472 }
473 /* Send event to KAFKA */
474 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
475 return err
476 }
477 logger.Debugw(ctx, "onu-drift-of-window-event-sent-to-kafka", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId})
478 return nil
479}
480
481func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
482 var de voltha.DeviceEvent
483 context := make(map[string]string)
484 /* Populating event context */
485 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
486 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
487 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
488
489 em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
490
491 /* Populating device event body */
492 de.Context = context
493 de.ResourceId = deviceID
494 if onuSignalDegrade.Status == statusCheckOn {
495 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
496 } else {
497 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
498 }
499 /* Send event to KAFKA */
500 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
501 return err
502 }
503 logger.Debugw(ctx, "onu-signal-degrade-event-sent-to-kafka", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
504 return nil
505}
506
507func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
508 var de voltha.DeviceEvent
509 context := make(map[string]string)
510 /* Populating event context */
511 em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
512
513 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
514 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
515 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
516 /* Populating device event body */
517 de.Context = context
518 de.ResourceId = deviceID
519 if onuSignalsFail.Status == statusCheckOn {
520 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
521 } else {
522 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
523 }
524 /* Send event to KAFKA */
525 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
526 return err
527 }
528 logger.Debugw(ctx, "onu-signals-fail-event-sent-to-kafka", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
529 return nil
530}
531
532func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
533 var de voltha.DeviceEvent
534 context := make(map[string]string)
535 /* Populating event context */
536 em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
537
538 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
539 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
540
541 /* Populating device event body */
542 de.Context = context
543 de.ResourceId = deviceID
544 if onuStartupFail.Status == statusCheckOn {
545 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
546 } else {
547 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
548 }
549 /* Send event to KAFKA */
550 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
551 return err
552 }
553 logger.Debugw(ctx, "onu-startup-fail-event-sent-to-kafka", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId})
554 return nil
555}
556
557func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
558 var de voltha.DeviceEvent
559 context := make(map[string]string)
560 /* Populating event context */
561 em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
562
563 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
564 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
565 /* Populating device event body */
566 de.Context = context
567 de.ResourceId = deviceID
568 if onuLOKI.Status == statusCheckOn {
569 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
570 } else {
571 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
572 }
573
574 /* Send event to KAFKA */
575 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs); err != nil {
576 return err
577 }
578 logger.Debugw(ctx, "onu-loss-of-key-sync-event-sent-to-kafka", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
579 return nil
580}
581
582// oltIntfOperIndication handles Up and Down state of an OLT PON ports
583func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
584 portNo := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
585 if port, err := em.handler.coreProxy.GetDevicePort(ctx, deviceID, portNo); err != nil {
586 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "error": err})
587 } else if port.AdminState != common.AdminState_ENABLED {
588 logger.Debugw(ctx, "port-disable/enable-event-not-generated--the-port-is-not-enabled-by-operator", log.Fields{"device-id": deviceID, "port": port})
589 return
590 }
591 /* Populating event context */
592 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
593 /* Populating device event body */
594 var de voltha.DeviceEvent
595 de.Context = context
596 de.ResourceId = deviceID
597
598 if ifindication.GetOperState() == operationStateDown {
599 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
600 } else if ifindication.OperState == operationStateUp {
601 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
602 }
603 /* Send event to KAFKA */
604 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
605 _ = olterrors.NewErrCommunication("send-olt-intf-oper-status-event", log.Fields{"device-id": deviceID, "intf-id": ifindication.IntfId, "oper-state": ifindication.OperState}, err).LogAt(log.WarnLevel)
606 return
607 }
608 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
609}
610
611func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
612 var de voltha.DeviceEvent
613 context := make(map[string]string)
614 /* Populating event context */
615 em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
616
617 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
618 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
619 /* Populating device event body */
620 de.Context = context
621 de.ResourceId = deviceID
622 if onuDFI.Status == statusCheckOn {
623 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
624 } else {
625 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
626 }
627 /* Send event to KAFKA */
628 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
629 return err
630 }
631 logger.Debugw(ctx, "onu-deactivation-failure-event-sent-to-kafka", log.Fields{"onu-id": onuDFI.OnuId, "intf-id": onuDFI.IntfId})
632 return nil
633}
634
635func (em *OpenOltEventMgr) onuRemoteDefectIndication(ctx context.Context, onuID uint32, intfID uint32, rdiCount uint64, status string, deviceID string, raisedTs int64) error {
636 /* Populating event context */
637 context := map[string]string{
638 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
639 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
640 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
641 }
642 em.populateContextWithSerialDeviceID(context, intfID, onuID)
643
644 /* Populating device event body */
645 de := &voltha.DeviceEvent{
646 Context: context,
647 ResourceId: deviceID,
648 }
649 if status == statusCheckOn {
650 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
651 } else {
652 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
653 }
654 /* Send event to KAFKA */
655 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
656 return err
657 }
658 logger.Debugw(ctx, "onu-remote-defect-event-sent-to-kafka", log.Fields{"onu-id": onuID, "intf-id": intfID})
659 return nil
660}
661
662func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
663 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
664 if !found {
665 return errors.New("unknown-onu-device")
666 }
667 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
668 if !onuDevice.(*OnuDevice).rdiRaised {
669 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
670 return err
671 }
672 onuDevice.(*OnuDevice).rdiRaised = true
673 return nil
674 }
675 logger.Debugw(ctx, "onu-remote-defect-already-raised", log.Fields{"onu-id": onuIPS.OnuId, "intf-id": onuIPS.IntfId})
676 } else {
677 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
678 return err
679 }
680 onuDevice.(*OnuDevice).rdiRaised = false
681 }
682 return nil
683}
684
685func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
686 /* Populating event context */
687 context := map[string]string{
688 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
689 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
690 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
691 }
692 em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
693
694 /* Populating device event body */
695 de := &voltha.DeviceEvent{
696 Context: context,
697 ResourceId: deviceID,
698 }
699 if onuGCD.Status == statusCheckOn {
700 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
701 } else {
702 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
703 }
704 /* Send event to KAFKA */
705 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
706 return err
707 }
708 logger.Debugw(ctx, "onu-loss-of-gem-channel-delineation-event-sent-to-kafka", log.Fields{"onu-id": onuGCD.OnuId, "intf-id": onuGCD.IntfId})
709 return nil
710}
711
712func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
713 /* Populating event context */
714 context := map[string]string{
715 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
716 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
717 }
718 em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
719 /* Populating device event body */
720 de := &voltha.DeviceEvent{
721 Context: context,
722 ResourceId: deviceID,
723 }
724 if onuErr.Status == statusCheckOn {
725 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
726 } else {
727 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
728 }
729 /* Send event to KAFKA */
730 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
731 return err
732 }
733 logger.Debugw(ctx, "onu-physical-equipment-error-event-sent-to-kafka", log.Fields{"onu-id": onuErr.OnuId, "intf-id": onuErr.IntfId})
734 return nil
735}
736
737func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
738 /* Populating event context */
739 context := map[string]string{
740 ContextOnuOnuID: strconv.FormatUint(uint64(onuLOA.OnuId), base10),
741 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
742 }
743 em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
744
745 /* Populating device event body */
746 de := &voltha.DeviceEvent{
747 Context: context,
748 ResourceId: deviceID,
749 }
750 if onuLOA.Status == statusCheckOn {
751 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
752 } else {
753 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
754 }
755 /* Send event to KAFKA */
756 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
757 return err
758 }
759 logger.Debugw(ctx, "onu-physical-equipment-error-event-sent-to-kafka", log.Fields{"onu-id": onuLOA.OnuId, "intf-id": onuLOA.IntfId})
760 return nil
761}
762
763func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
764 /* Populating event context */
765 context := map[string]string{
766 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
767 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
768 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
769 }
770 em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
771
772 /* Populating device event body */
773 de := &voltha.DeviceEvent{
774 Context: context,
775 ResourceId: deviceID,
776 }
777 if onuDRE.Status == statusCheckOn {
778 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
779 } else {
780 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
781 }
782 /* Send event to KAFKA */
783 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
784 return err
785 }
786 logger.Debugw(ctx, "onu-differential-reach-exceeded–event-sent-to-kafka", log.Fields{"onu-id": onuDRE.OnuId, "intf-id": onuDRE.IntfId})
787 return nil
788}