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 ( |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 21 | ctx "context" |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 22 | "fmt" |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 23 | "strconv" |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 24 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 25 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
| 26 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 27 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 28 | "github.com/opencord/voltha-protos/v3/go/common" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 29 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
| 30 | "github.com/opencord/voltha-protos/v3/go/voltha" |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | const ( |
Devmalya Paul | 41a762d | 2020-03-01 18:56:54 -0500 | [diff] [blame] | 34 | onuDiscoveryEvent = "ONU_DISCOVERY" |
| 35 | onuLosEvent = "ONU_LOSS_OF_SIGNAL" |
| 36 | onuLobEvent = "ONU_LOSS_OF_BURST" |
| 37 | onuLopcMissEvent = "ONU_LOPC_MISS" |
| 38 | onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR" |
| 39 | oltLosEvent = "OLT_LOSS_OF_SIGNAL" |
| 40 | oltIndicationDown = "OLT_DOWN_INDICATION" |
| 41 | onuDyingGaspEvent = "ONU_DYING_GASP" |
| 42 | onuSignalsFailEvent = "ONU_SIGNALS_FAIL" |
| 43 | onuStartupFailEvent = "ONU_STARTUP_FAIL" |
| 44 | onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE" |
| 45 | onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW" |
| 46 | onuActivationFailEvent = "ONU_ACTIVATION_FAIL" |
| 47 | onuProcessingErrorEvent = "ONU_PROCESSING_ERROR" |
| 48 | onuTiwiEvent = "ONU_TRANSMISSION_WARNING" |
| 49 | onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL" |
| 50 | onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC" |
| 51 | onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME" |
| 52 | onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM" |
| 53 | ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN" |
| 54 | onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE" |
| 55 | onuRemoteDefectIndication = "ONU_REMOTE_DEFECT" |
| 56 | onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION" |
| 57 | onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR" |
| 58 | onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT" |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 59 | ) |
| 60 | |
| 61 | const ( |
| 62 | pon = voltha.EventSubCategory_PON |
| 63 | olt = voltha.EventSubCategory_OLT |
| 64 | ont = voltha.EventSubCategory_ONT |
| 65 | onu = voltha.EventSubCategory_ONU |
| 66 | nni = voltha.EventSubCategory_NNI |
| 67 | service = voltha.EventCategory_SERVICE |
| 68 | security = voltha.EventCategory_SECURITY |
| 69 | equipment = voltha.EventCategory_EQUIPMENT |
| 70 | processing = voltha.EventCategory_PROCESSING |
| 71 | environment = voltha.EventCategory_ENVIRONMENT |
| 72 | communication = voltha.EventCategory_COMMUNICATION |
| 73 | ) |
| 74 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 75 | const ( |
| 76 | // statusCheckOn represents status check On |
| 77 | statusCheckOn = "on" |
| 78 | // statusCheckOff represents status check Off |
| 79 | statusCheckOff = "off" |
| 80 | // operationStateUp represents operation state Up |
| 81 | operationStateUp = "up" |
| 82 | // operationStateDown represents operation state Down |
| 83 | operationStateDown = "down" |
| 84 | // base10 represents base 10 conversion |
| 85 | base10 = 10 |
| 86 | ) |
| 87 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 88 | // OpenOltEventMgr struct contains |
| 89 | type OpenOltEventMgr struct { |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 90 | eventProxy adapterif.EventProxy |
Devmalya Paul | 90ca301 | 2019-09-02 21:55:45 -0400 | [diff] [blame] | 91 | handler *DeviceHandler |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // 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] | 95 | func NewEventMgr(eventProxy adapterif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 96 | var em OpenOltEventMgr |
| 97 | em.eventProxy = eventProxy |
Devmalya Paul | 90ca301 | 2019-09-02 21:55:45 -0400 | [diff] [blame] | 98 | em.handler = handler |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 99 | return &em |
| 100 | } |
| 101 | |
| 102 | // ProcessEvents is function to process and publish OpenOLT event |
Devmalya Paul | 41a762d | 2020-03-01 18:56:54 -0500 | [diff] [blame] | 103 | // nolint: gocyclo |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 104 | func (em *OpenOltEventMgr) ProcessEvents(alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) error { |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 105 | var err error |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 106 | switch alarmInd.Data.(type) { |
| 107 | case *oop.AlarmIndication_LosInd: |
| 108 | log.Infow("Received LOS indication", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 109 | err = em.oltLosIndication(alarmInd.GetLosInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 110 | case *oop.AlarmIndication_OnuAlarmInd: |
| 111 | log.Infow("Received onu alarm indication ", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 112 | err = em.onuAlarmIndication(alarmInd.GetOnuAlarmInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 113 | case *oop.AlarmIndication_DyingGaspInd: |
| 114 | log.Infow("Received dying gasp indication", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 115 | err = em.onuDyingGaspIndication(alarmInd.GetDyingGaspInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 116 | case *oop.AlarmIndication_OnuActivationFailInd: |
| 117 | log.Infow("Received onu activation fail indication ", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 118 | err = em.onuActivationFailIndication(alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 119 | case *oop.AlarmIndication_OnuLossOmciInd: |
| 120 | log.Infow("Received onu loss omci indication ", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 121 | err = em.onuLossOmciIndication(alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 122 | case *oop.AlarmIndication_OnuDriftOfWindowInd: |
| 123 | log.Infow("Received onu drift of window indication ", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 124 | err = em.onuDriftOfWindowIndication(alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 125 | case *oop.AlarmIndication_OnuSignalDegradeInd: |
| 126 | log.Infow("Received onu signal degrade indication ", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 127 | err = em.onuSignalDegradeIndication(alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 128 | case *oop.AlarmIndication_OnuSignalsFailInd: |
| 129 | log.Infow("Received onu signal fail indication ", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 130 | err = em.onuSignalsFailIndication(alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs) |
Naga Manjunath | f6f7464 | 2020-01-13 21:37:28 +0530 | [diff] [blame] | 131 | case *oop.AlarmIndication_OnuStartupFailInd: |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 132 | log.Infow("Received onu startup fail indication ", log.Fields{"alarm_ind": alarmInd}) |
Naga Manjunath | f6f7464 | 2020-01-13 21:37:28 +0530 | [diff] [blame] | 133 | err = em.onuStartupFailedIndication(alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 134 | case *oop.AlarmIndication_OnuTiwiInd: |
| 135 | log.Infow("Received onu transmission warning indication ", log.Fields{"alarm_ind": alarmInd}) |
| 136 | log.Infow("Not implemented yet", log.Fields{"alarm_ind": "Onu-Transmission-indication"}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 137 | case *oop.AlarmIndication_OnuLossOfSyncFailInd: |
| 138 | log.Infow("Received onu Loss of Sync Fail indication ", log.Fields{"alarm_ind": alarmInd}) |
| 139 | err = em.onuLossOfSyncIndication(alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs) |
| 140 | case *oop.AlarmIndication_OnuItuPonStatsInd: |
| 141 | log.Infow("Received onu Itu Pon Stats indication ", log.Fields{"alarm_ind": alarmInd}) |
| 142 | log.Infow("Not implemented yet", log.Fields{"alarm_ind": alarmInd}) |
Devmalya Paul | 6f063a6 | 2020-02-19 19:19:06 -0500 | [diff] [blame] | 143 | case *oop.AlarmIndication_OnuRemoteDefectInd: |
| 144 | log.Infow("Received onu remote defect indication ", log.Fields{"alarm_ind": alarmInd}) |
| 145 | err = em.onuRemoteDefectIndication(alarmInd.GetOnuRemoteDefectInd(), deviceID, raisedTs) |
Devmalya Paul | 1abc34e | 2020-02-04 20:48:06 -0500 | [diff] [blame] | 146 | case *oop.AlarmIndication_OnuDeactivationFailureInd: |
| 147 | log.Infow("Received onu deactivation failure indication ", log.Fields{"alarm_ind": alarmInd}) |
| 148 | err = em.onuDeactivationFailureIndication(alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs) |
Devmalya Paul | 41a762d | 2020-03-01 18:56:54 -0500 | [diff] [blame] | 149 | case *oop.AlarmIndication_OnuLossGemDelineationInd: |
| 150 | log.Infow("Received onu loss of GEM channel delineation indication ", log.Fields{"alarm_ind": alarmInd}) |
| 151 | err = em.onuLossOfGEMChannelDelineationIndication(alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs) |
| 152 | case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd: |
| 153 | log.Infow("Received onu physical equipment error indication ", log.Fields{"alarm_ind": alarmInd}) |
| 154 | err = em.onuPhysicalEquipmentErrorIndication(alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs) |
| 155 | case *oop.AlarmIndication_OnuLossOfAckInd: |
| 156 | log.Infow("Received onu loss of acknowledgement indication ", log.Fields{"alarm_ind": alarmInd}) |
| 157 | err = em.onuLossOfAcknowledgementIndication(alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 158 | default: |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 159 | err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 160 | } |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 161 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 162 | return olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).Log() |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 163 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 164 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 165 | } |
| 166 | |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 167 | // oltUpDownIndication handles Up and Down state of an OLT |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 168 | func (em *OpenOltEventMgr) oltUpDownIndication(oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error { |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 169 | var de voltha.DeviceEvent |
| 170 | context := make(map[string]string) |
| 171 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 172 | context["oper-state"] = oltIndication.OperState |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 173 | /* Populating device event body */ |
| 174 | de.Context = context |
| 175 | de.ResourceId = deviceID |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 176 | if oltIndication.OperState == operationStateDown { |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 177 | de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT") |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 178 | } else if oltIndication.OperState == operationStateUp { |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 179 | de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT") |
| 180 | } |
| 181 | /* Send event to KAFKA */ |
| 182 | if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 183 | return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err) |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 184 | } |
| 185 | log.Infow("OLT UpDown event sent to KAFKA", log.Fields{}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 186 | return nil |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 189 | // OnuDiscoveryIndication is an exported method to handle ONU discovery event |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 190 | func (em *OpenOltEventMgr) OnuDiscoveryIndication(onuDisc *oop.OnuDiscIndication, deviceID string, OnuID uint32, serialNumber string, raisedTs int64) error { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 191 | var de voltha.DeviceEvent |
| 192 | context := make(map[string]string) |
| 193 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 194 | context["onu-id"] = strconv.FormatUint(uint64(OnuID), base10) |
| 195 | context["intf-id"] = strconv.FormatUint(uint64(onuDisc.IntfId), base10) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 196 | context["serial-number"] = serialNumber |
| 197 | /* Populating device event body */ |
| 198 | de.Context = context |
| 199 | de.ResourceId = deviceID |
| 200 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT") |
| 201 | /* Send event to KAFKA */ |
| 202 | if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 203 | return olterrors.NewErrCommunication("send-onu-discovery-event", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId}, err) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 204 | } |
| 205 | log.Infow("ONU discovery event sent to KAFKA", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 206 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 209 | func (em *OpenOltEventMgr) oltLosIndication(oltLos *oop.LosIndication, deviceID string, raisedTs int64) error { |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame^] | 210 | var err error = nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 211 | var de voltha.DeviceEvent |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame^] | 212 | var alarmInd oop.OnuAlarmIndication |
| 213 | ponIntdID := PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT) |
| 214 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 215 | context := make(map[string]string) |
| 216 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 217 | context["intf-id"] = strconv.FormatUint(uint64(oltLos.IntfId), base10) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 218 | /* Populating device event body */ |
| 219 | de.Context = context |
| 220 | de.ResourceId = deviceID |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 221 | if oltLos.Status == statusCheckOn { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 222 | de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT") |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame^] | 223 | |
| 224 | /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication |
| 225 | with "los_status: on" should be raised for each Onu connected to the PON |
| 226 | but BAL does not raise this Alarm hence manually sending OnuLosRaise event |
| 227 | for all the ONU's connected to PON on receiving LoSIndication for PON */ |
| 228 | em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool { |
| 229 | if onuInCache.(*OnuDevice).intfID == ponIntdID { |
| 230 | alarmInd.IntfId = ponIntdID |
| 231 | alarmInd.OnuId = onuInCache.(*OnuDevice).onuID |
| 232 | alarmInd.LosStatus = statusCheckOn |
| 233 | err = em.onuAlarmIndication(&alarmInd, deviceID, raisedTs) |
| 234 | } |
| 235 | return true |
| 236 | }) |
| 237 | if err != nil { |
| 238 | /* Return if any error encountered while processing ONU LoS Event*/ |
| 239 | return err |
| 240 | } |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 241 | } else { |
| 242 | de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT") |
| 243 | } |
| 244 | /* Send event to KAFKA */ |
| 245 | if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil { |
| 246 | log.Errorw("Failed to send OLT loss of signal event", log.Fields{"intf-id": oltLos.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 247 | return err |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 248 | } |
| 249 | log.Infow("OLT LOS event sent to KAFKA", log.Fields{"intf-id": oltLos.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 250 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 253 | func (em *OpenOltEventMgr) onuDyingGaspIndication(dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 254 | var de voltha.DeviceEvent |
Devmalya Paul | 90ca301 | 2019-09-02 21:55:45 -0400 | [diff] [blame] | 255 | var serialNumber string |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 256 | context := make(map[string]string) |
| 257 | /* Populating event context */ |
Devmalya Paul | 90ca301 | 2019-09-02 21:55:45 -0400 | [diff] [blame] | 258 | serialNumber = "" |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 259 | onu := em.handler.formOnuKey(dgi.IntfId, dgi.OnuId) |
| 260 | if onu, ok := em.handler.onus.Load(onu); ok { |
| 261 | serialNumber = onu.(*OnuDevice).serialNumber |
Devmalya Paul | 90ca301 | 2019-09-02 21:55:45 -0400 | [diff] [blame] | 262 | } |
| 263 | context["serial-number"] = serialNumber |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 264 | context["intf-id"] = strconv.FormatUint(uint64(dgi.IntfId), base10) |
| 265 | context["onu-id"] = strconv.FormatUint(uint64(dgi.OnuId), base10) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 266 | /* Populating device event body */ |
| 267 | de.Context = context |
| 268 | de.ResourceId = deviceID |
Thomas Lee S | f68399e | 2020-02-11 15:41:38 +0530 | [diff] [blame] | 269 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT") |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 270 | /* Send event to KAFKA */ |
| 271 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 272 | log.Errorw("Failed to send ONU Dying gasp event", log.Fields{"intf-id": dgi.IntfId, "onu-id": dgi.OnuId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 273 | return err |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 274 | } |
| 275 | log.Infow("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] | 276 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 277 | } |
| 278 | |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame^] | 279 | //wasLosRaised checks whether los raised already. If already raised returns true else false |
| 280 | func (em *OpenOltEventMgr) wasLosRaised(onuAlarm *oop.OnuAlarmIndication) bool { |
| 281 | onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId) |
| 282 | if onuInCache, ok := em.handler.onus.Load(onuKey); ok { |
| 283 | log.Debugw("onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId}) |
| 284 | |
| 285 | if onuAlarm.LosStatus == statusCheckOn { |
| 286 | if onuInCache.(*OnuDevice).losRaised { |
| 287 | log.Warnw("onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId, |
| 288 | "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus}) |
| 289 | return true |
| 290 | } |
| 291 | return false |
| 292 | } |
| 293 | } |
| 294 | return true |
| 295 | } |
| 296 | |
| 297 | //wasLosCleared checks whether los cleared already. If already cleared returns true else false |
| 298 | func (em *OpenOltEventMgr) wasLosCleared(onuAlarm *oop.OnuAlarmIndication) bool { |
| 299 | onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId) |
| 300 | if onuInCache, ok := em.handler.onus.Load(onuKey); ok { |
| 301 | log.Debugw("onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId}) |
| 302 | |
| 303 | if onuAlarm.LosStatus == statusCheckOff { |
| 304 | if !onuInCache.(*OnuDevice).losRaised { |
| 305 | log.Warnw("onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId, |
| 306 | "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus}) |
| 307 | return true |
| 308 | } |
| 309 | return false |
| 310 | } |
| 311 | } |
| 312 | return true |
| 313 | } |
| 314 | |
| 315 | func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string { |
| 316 | var deviceEventName string |
| 317 | if onuAlarm.LosStatus == statusCheckOn { |
| 318 | deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT") |
| 319 | } else if onuAlarm.LosStatus == statusCheckOff { |
| 320 | deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT") |
| 321 | } else if onuAlarm.LobStatus == statusCheckOn { |
| 322 | deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT") |
| 323 | } else if onuAlarm.LobStatus == statusCheckOff { |
| 324 | deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT") |
| 325 | } else if onuAlarm.LopcMissStatus == statusCheckOn { |
| 326 | deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT") |
| 327 | } else if onuAlarm.LopcMissStatus == statusCheckOff { |
| 328 | deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT") |
| 329 | } else if onuAlarm.LopcMicErrorStatus == statusCheckOn { |
| 330 | deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT") |
| 331 | } else if onuAlarm.LopcMicErrorStatus == statusCheckOff { |
| 332 | deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT") |
| 333 | } else if onuAlarm.LofiStatus == statusCheckOn { |
| 334 | deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT") |
| 335 | } else if onuAlarm.LofiStatus == statusCheckOff { |
| 336 | deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT") |
| 337 | } else if onuAlarm.LoamiStatus == statusCheckOn { |
| 338 | deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT") |
| 339 | } else if onuAlarm.LoamiStatus == statusCheckOff { |
| 340 | deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT") |
| 341 | } |
| 342 | return deviceEventName |
| 343 | } |
| 344 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 345 | func (em *OpenOltEventMgr) onuAlarmIndication(onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 346 | var de voltha.DeviceEvent |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame^] | 347 | var serialNumber string |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 348 | context := make(map[string]string) |
| 349 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 350 | context["intf-id"] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10) |
| 351 | context["onu-id"] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10) |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame^] | 352 | serialNumber = "" |
| 353 | onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId) |
| 354 | if onu, ok := em.handler.onus.Load(onuKey); ok { |
| 355 | serialNumber = onu.(*OnuDevice).serialNumber |
| 356 | } |
| 357 | context["serial-number"] = serialNumber |
| 358 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 359 | /* Populating device event body */ |
| 360 | de.Context = context |
| 361 | de.ResourceId = deviceID |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame^] | 362 | de.DeviceEventName = em.getDeviceEventName(onuAlarm) |
| 363 | |
| 364 | switch onuAlarm.LosStatus { |
| 365 | case statusCheckOn: |
| 366 | if em.wasLosRaised(onuAlarm) { |
| 367 | /* No need to raise Onu Los Event as it might have already raised |
| 368 | or Onu might have deleted */ |
| 369 | return nil |
| 370 | } |
| 371 | onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId) |
| 372 | if onuInCache, ok := em.handler.onus.Load(onuKey); ok { |
| 373 | /* Update onu device with LoS raised state as true */ |
| 374 | em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType, |
| 375 | onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID, |
| 376 | onuInCache.(*OnuDevice).proxyDeviceID, true)) |
| 377 | } |
| 378 | case statusCheckOff: |
| 379 | if em.wasLosCleared(onuAlarm) { |
| 380 | /* No need to clear Onu Los Event as it might have already cleared |
| 381 | or Onu might have deleted */ |
| 382 | return nil |
| 383 | } |
| 384 | onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId) |
| 385 | if onuInCache, ok := em.handler.onus.Load(onuKey); ok { |
| 386 | /* Update onu device with LoS raised state as false */ |
| 387 | em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType, |
| 388 | onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID, |
| 389 | onuInCache.(*OnuDevice).proxyDeviceID, false)) |
| 390 | } |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 391 | } |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame^] | 392 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 393 | /* Send event to KAFKA */ |
| 394 | if err := em.eventProxy.SendDeviceEvent(&de, communication, onu, raisedTs); err != nil { |
| 395 | log.Errorw("Failed to send ONU Los event", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 396 | return err |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 397 | } |
| 398 | log.Infow("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] | 399 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 400 | } |
| 401 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 402 | func (em *OpenOltEventMgr) onuActivationFailIndication(oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) error { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 403 | var de voltha.DeviceEvent |
| 404 | context := make(map[string]string) |
| 405 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 406 | context["intf-id"] = strconv.FormatUint(uint64(oaf.IntfId), base10) |
| 407 | context["onu-id"] = strconv.FormatUint(uint64(oaf.OnuId), base10) |
Scott Baker | d4df118 | 2020-02-05 11:38:42 -0800 | [diff] [blame] | 408 | context["fail-reason"] = strconv.FormatUint(uint64(oaf.FailReason), base10) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 409 | /* Populating device event body */ |
| 410 | de.Context = context |
| 411 | de.ResourceId = deviceID |
| 412 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT") |
| 413 | /* Send event to KAFKA */ |
| 414 | if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil { |
| 415 | log.Errorw("Failed to send ONU activation failure event", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 416 | return err |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 417 | } |
| 418 | log.Infow("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] | 419 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 420 | } |
| 421 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 422 | func (em *OpenOltEventMgr) onuLossOmciIndication(onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 423 | var de voltha.DeviceEvent |
| 424 | context := make(map[string]string) |
| 425 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 426 | context["intf-id"] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10) |
| 427 | context["onu-id"] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 428 | /* Populating device event body */ |
| 429 | de.Context = context |
| 430 | de.ResourceId = deviceID |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 431 | if onuLossOmci.Status == statusCheckOn { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 432 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT") |
| 433 | } else { |
| 434 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT") |
| 435 | } |
| 436 | /* Send event to KAFKA */ |
| 437 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 438 | log.Errorw("Failed to send ONU loss of OMCI channel event", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 439 | return err |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 440 | } |
| 441 | log.Infow("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] | 442 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 443 | } |
| 444 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 445 | func (em *OpenOltEventMgr) onuDriftOfWindowIndication(onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 446 | var de voltha.DeviceEvent |
| 447 | context := make(map[string]string) |
| 448 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 449 | context["intf-id"] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10) |
| 450 | context["onu-id"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10) |
Scott Baker | d4df118 | 2020-02-05 11:38:42 -0800 | [diff] [blame] | 451 | context["drift"] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10) |
| 452 | context["new-eqd"] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10) |
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 |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 456 | if onuDriftWindow.Status == statusCheckOn { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 457 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT") |
| 458 | } else { |
| 459 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT") |
| 460 | } |
| 461 | /* Send event to KAFKA */ |
| 462 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 463 | log.Errorw("Failed to send ONU drift of window event", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 464 | return err |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 465 | } |
| 466 | log.Infow("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] | 467 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 468 | } |
| 469 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 470 | func (em *OpenOltEventMgr) onuSignalDegradeIndication(onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 471 | var de voltha.DeviceEvent |
| 472 | context := make(map[string]string) |
| 473 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 474 | context["intf-id"] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10) |
| 475 | context["onu-id"] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10) |
Scott Baker | d4df118 | 2020-02-05 11:38:42 -0800 | [diff] [blame] | 476 | context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10) |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 477 | /* Populating device event body */ |
| 478 | de.Context = context |
| 479 | de.ResourceId = deviceID |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 480 | if onuSignalDegrade.Status == statusCheckOn { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 481 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT") |
| 482 | } else { |
| 483 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT") |
| 484 | } |
| 485 | /* Send event to KAFKA */ |
| 486 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 487 | log.Errorw("Failed to send ONU signals degrade event", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 488 | return err |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 489 | } |
| 490 | log.Infow("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] | 491 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 492 | } |
| 493 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 494 | func (em *OpenOltEventMgr) onuSignalsFailIndication(onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 495 | var de voltha.DeviceEvent |
| 496 | context := make(map[string]string) |
| 497 | /* Populating event context */ |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 498 | context["onu-id"] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10) |
| 499 | context["intf-id"] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10) |
| 500 | context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10) |
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 onuSignalsFail.Status == statusCheckOn { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 505 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT") |
| 506 | } else { |
| 507 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT") |
| 508 | } |
| 509 | /* Send event to KAFKA */ |
| 510 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 511 | log.Errorw("Failed to send ONU signals fail event", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId}) |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 512 | return err |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 513 | } |
| 514 | log.Infow("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] | 515 | return nil |
| 516 | } |
| 517 | |
Naga Manjunath | f6f7464 | 2020-01-13 21:37:28 +0530 | [diff] [blame] | 518 | func (em *OpenOltEventMgr) onuStartupFailedIndication(onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error { |
| 519 | var de voltha.DeviceEvent |
| 520 | context := make(map[string]string) |
| 521 | /* Populating event context */ |
| 522 | context["onu-id"] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10) |
| 523 | context["intf-id"] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10) |
| 524 | |
| 525 | /* Populating device event body */ |
| 526 | de.Context = context |
| 527 | de.ResourceId = deviceID |
| 528 | if onuStartupFail.Status == statusCheckOn { |
| 529 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT") |
| 530 | } else { |
| 531 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT") |
| 532 | } |
| 533 | /* Send event to KAFKA */ |
| 534 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 535 | log.Errorw("Failed to send ONU startup fail event", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId}) |
| 536 | return err |
| 537 | } |
| 538 | log.Infow("ONU startup fail event sent to KAFKA", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId}) |
| 539 | return nil |
| 540 | } |
| 541 | |
Naga Manjunath | 9546b91 | 2019-11-28 20:56:20 +0530 | [diff] [blame] | 542 | func (em *OpenOltEventMgr) onuLossOfSyncIndication(onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error { |
| 543 | var de voltha.DeviceEvent |
| 544 | context := make(map[string]string) |
| 545 | /* Populating event context */ |
| 546 | context["onu-id"] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10) |
| 547 | context["intf-id"] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10) |
| 548 | /* Populating device event body */ |
| 549 | de.Context = context |
| 550 | de.ResourceId = deviceID |
| 551 | if onuLOKI.Status == statusCheckOn { |
| 552 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT") |
| 553 | } else { |
| 554 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT") |
| 555 | } |
| 556 | |
| 557 | /* Send event to KAFKA */ |
| 558 | if err := em.eventProxy.SendDeviceEvent(&de, security, onu, raisedTs); err != nil { |
| 559 | log.Errorw("Failed to send ONU loss of key sync event", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId}) |
| 560 | return err |
| 561 | } |
| 562 | log.Infow("ONU loss of key sync event sent to KAFKA", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId}) |
| 563 | return nil |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 564 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 565 | |
| 566 | // oltIntfOperIndication handles Up and Down state of an OLT PON ports |
| 567 | func (em *OpenOltEventMgr) oltIntfOperIndication(ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) { |
| 568 | var de voltha.DeviceEvent |
| 569 | context := make(map[string]string) |
| 570 | portID := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT) |
| 571 | device, err := em.handler.coreProxy.GetDevice(ctx.Background(), deviceID, deviceID) |
| 572 | if err != nil { |
| 573 | log.Errorw("Error while fetching Device object", log.Fields{"DeviceId": deviceID}) |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 574 | return |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 575 | } |
| 576 | for _, port := range device.Ports { |
| 577 | if port.PortNo == portID { |
| 578 | // Events are suppressed if the Port Adminstate is not enabled. |
| 579 | if port.AdminState != common.AdminState_ENABLED { |
| 580 | log.Infow("Port disable/enable event not generated because, The port is not enabled by operator", log.Fields{"deviceId": deviceID, "port": port}) |
| 581 | return |
| 582 | } |
| 583 | break |
| 584 | } |
| 585 | } |
| 586 | /* Populating event context */ |
| 587 | context["oper-state"] = ifindication.GetOperState() |
| 588 | /* Populating device event body */ |
| 589 | de.Context = context |
| 590 | de.ResourceId = deviceID |
| 591 | |
| 592 | if ifindication.GetOperState() == operationStateDown { |
| 593 | de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT") |
| 594 | } else if ifindication.OperState == operationStateUp { |
| 595 | de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT") |
| 596 | } |
| 597 | /* Send event to KAFKA */ |
| 598 | if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 599 | 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] | 600 | } |
| 601 | log.Info("sent-olt-intf-oper-status-event-to-kafka") |
| 602 | } |
Devmalya Paul | 1abc34e | 2020-02-04 20:48:06 -0500 | [diff] [blame] | 603 | |
| 604 | func (em *OpenOltEventMgr) onuDeactivationFailureIndication(onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error { |
| 605 | var de voltha.DeviceEvent |
| 606 | context := make(map[string]string) |
| 607 | /* Populating event context */ |
| 608 | context["onu-id"] = strconv.FormatUint(uint64(onuDFI.OnuId), base10) |
| 609 | context["intf-id"] = strconv.FormatUint(uint64(onuDFI.IntfId), base10) |
| 610 | context["failure-reason"] = strconv.FormatUint(uint64(onuDFI.FailReason), base10) |
| 611 | /* Populating device event body */ |
| 612 | de.Context = context |
| 613 | de.ResourceId = deviceID |
| 614 | de.DeviceEventName = onuDeactivationFailureEvent |
| 615 | |
| 616 | /* Send event to KAFKA */ |
| 617 | if err := em.eventProxy.SendDeviceEvent(&de, equipment, onu, raisedTs); err != nil { |
| 618 | log.Errorw("Failed to send ONU deactivation failure event", log.Fields{"onu-id": onuDFI.OnuId, "intf-id": onuDFI.IntfId}) |
| 619 | return err |
| 620 | } |
| 621 | log.Infow("ONU deactivation failure event sent to KAFKA", log.Fields{"onu-id": onuDFI.OnuId, "intf-id": onuDFI.IntfId}) |
| 622 | return nil |
| 623 | } |
Devmalya Paul | 6f063a6 | 2020-02-19 19:19:06 -0500 | [diff] [blame] | 624 | |
| 625 | func (em *OpenOltEventMgr) onuRemoteDefectIndication(onuRDI *oop.OnuRemoteDefectIndication, deviceID string, raisedTs int64) error { |
| 626 | /* Populating event context */ |
| 627 | context := map[string]string{ |
| 628 | "onu-id": strconv.FormatUint(uint64(onuRDI.OnuId), base10), |
| 629 | "intf-id": strconv.FormatUint(uint64(onuRDI.IntfId), base10), |
| 630 | "rdi-errors": strconv.FormatUint(uint64(onuRDI.RdiErrors), base10), |
| 631 | } |
| 632 | /* Populating device event body */ |
| 633 | de := &voltha.DeviceEvent{ |
| 634 | Context: context, |
| 635 | ResourceId: deviceID, |
| 636 | DeviceEventName: onuRemoteDefectIndication, |
| 637 | } |
| 638 | /* Send event to KAFKA */ |
| 639 | if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil { |
Devmalya Paul | 6f063a6 | 2020-02-19 19:19:06 -0500 | [diff] [blame] | 640 | return err |
| 641 | } |
Devmalya Paul | 41a762d | 2020-03-01 18:56:54 -0500 | [diff] [blame] | 642 | log.Debugw("ONU remote defect event sent to KAFKA", log.Fields{"onu-id": onuRDI.OnuId, "intf-id": onuRDI.IntfId}) |
| 643 | return nil |
| 644 | } |
| 645 | |
| 646 | func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error { |
| 647 | /* Populating event context */ |
| 648 | context := map[string]string{ |
| 649 | "onu-id": strconv.FormatUint(uint64(onuGCD.OnuId), base10), |
| 650 | "intf-id": strconv.FormatUint(uint64(onuGCD.IntfId), base10), |
| 651 | "delineation-errors": strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10), |
| 652 | } |
| 653 | /* Populating device event body */ |
| 654 | de := &voltha.DeviceEvent{ |
| 655 | Context: context, |
| 656 | ResourceId: deviceID, |
| 657 | } |
| 658 | if onuGCD.Status == statusCheckOn { |
| 659 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT") |
| 660 | } else { |
| 661 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT") |
| 662 | } |
| 663 | /* Send event to KAFKA */ |
| 664 | if err := em.eventProxy.SendDeviceEvent(de, communication, onu, raisedTs); err != nil { |
| 665 | return err |
| 666 | } |
| 667 | log.Debugw("ONU loss of GEM channel delineation event sent to KAFKA", log.Fields{"onu-id": onuGCD.OnuId, "intf-id": onuGCD.IntfId}) |
| 668 | return nil |
| 669 | } |
| 670 | |
| 671 | func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error { |
| 672 | /* Populating event context */ |
| 673 | context := map[string]string{ |
| 674 | "onu-id": strconv.FormatUint(uint64(onuErr.OnuId), base10), |
| 675 | "intf-id": strconv.FormatUint(uint64(onuErr.IntfId), base10), |
| 676 | } |
| 677 | /* Populating device event body */ |
| 678 | de := &voltha.DeviceEvent{ |
| 679 | Context: context, |
| 680 | ResourceId: deviceID, |
| 681 | } |
| 682 | if onuErr.Status == statusCheckOn { |
| 683 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT") |
| 684 | } else { |
| 685 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT") |
| 686 | } |
| 687 | /* Send event to KAFKA */ |
| 688 | if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil { |
| 689 | return err |
| 690 | } |
| 691 | log.Debugw("ONU physical equipment error event sent to KAFKA", log.Fields{"onu-id": onuErr.OnuId, "intf-id": onuErr.IntfId}) |
| 692 | return nil |
| 693 | } |
| 694 | |
| 695 | func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error { |
| 696 | /* Populating event context */ |
| 697 | context := map[string]string{ |
| 698 | "onu-id": strconv.FormatUint(uint64(onuLOA.OnuId), base10), |
| 699 | "intf-id": strconv.FormatUint(uint64(onuLOA.IntfId), base10), |
| 700 | } |
| 701 | /* Populating device event body */ |
| 702 | de := &voltha.DeviceEvent{ |
| 703 | Context: context, |
| 704 | ResourceId: deviceID, |
| 705 | } |
| 706 | if onuLOA.Status == statusCheckOn { |
| 707 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT") |
| 708 | } else { |
| 709 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT") |
| 710 | } |
| 711 | /* Send event to KAFKA */ |
| 712 | if err := em.eventProxy.SendDeviceEvent(de, equipment, onu, raisedTs); err != nil { |
| 713 | return err |
| 714 | } |
| 715 | log.Debugw("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] | 716 | return nil |
| 717 | } |