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