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 | |
| 17 | // Package adaptercore provides APIs for the openOLT adapter |
| 18 | package adaptercore |
| 19 | |
| 20 | import ( |
| 21 | "fmt" |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 22 | |
| 23 | "github.com/opencord/voltha-go/adapters/adapterif" |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 24 | "github.com/opencord/voltha-go/common/log" |
| 25 | oop "github.com/opencord/voltha-protos/go/openolt" |
| 26 | "github.com/opencord/voltha-protos/go/voltha" |
| 27 | ) |
| 28 | |
| 29 | const ( |
| 30 | onuDiscoveryEvent = "ONU_DISCOVERY" |
| 31 | onuLosEvent = "ONU_LOSS_OF_SIGNAL" |
| 32 | onuLobEvent = "ONU_LOSS_OF_BURST" |
| 33 | onuLopcMissEvent = "ONU_LOPC_MISS" |
| 34 | onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR" |
| 35 | oltLosEvent = "OLT_LOSS_OF_SIGNAL" |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 36 | oltIndicationDown = "OLT_DOWN_INDICATION" |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 37 | onuDyingGaspEvent = "ONU_DYING_GASP" |
| 38 | onuSignalsFailEvent = "ONU_SIGNALS_FAIL" |
| 39 | onuStartupFailEvent = "ONU_STARTUP_FAIL" |
| 40 | onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE" |
| 41 | onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW" |
| 42 | onuActivationFailEvent = "ONU_ACTIVATION_FAIL" |
| 43 | onuProcessingErrorEvent = "ONU_PROCESSING_ERROR" |
| 44 | onuTiwiEvent = "ONU_TRANSMISSION_WARNING" |
| 45 | onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL" |
| 46 | ) |
| 47 | |
| 48 | const ( |
| 49 | pon = voltha.EventSubCategory_PON |
| 50 | olt = voltha.EventSubCategory_OLT |
| 51 | ont = voltha.EventSubCategory_ONT |
| 52 | onu = voltha.EventSubCategory_ONU |
| 53 | nni = voltha.EventSubCategory_NNI |
| 54 | service = voltha.EventCategory_SERVICE |
| 55 | security = voltha.EventCategory_SECURITY |
| 56 | equipment = voltha.EventCategory_EQUIPMENT |
| 57 | processing = voltha.EventCategory_PROCESSING |
| 58 | environment = voltha.EventCategory_ENVIRONMENT |
| 59 | communication = voltha.EventCategory_COMMUNICATION |
| 60 | ) |
| 61 | |
| 62 | // OpenOltEventMgr struct contains |
| 63 | type OpenOltEventMgr struct { |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 64 | eventProxy adapterif.EventProxy |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | // NewEventMgr is a Function to get a new event manager struct for the OpenOLT to process and publish OpenOLT event |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 68 | func NewEventMgr(eventProxy adapterif.EventProxy) *OpenOltEventMgr { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 69 | var em OpenOltEventMgr |
| 70 | em.eventProxy = eventProxy |
| 71 | return &em |
| 72 | } |
| 73 | |
| 74 | // ProcessEvents is function to process and publish OpenOLT event |
| 75 | func (em *OpenOltEventMgr) ProcessEvents(alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) { |
| 76 | |
| 77 | switch alarmInd.Data.(type) { |
| 78 | case *oop.AlarmIndication_LosInd: |
| 79 | log.Infow("Received LOS indication", log.Fields{"alarm_ind": alarmInd}) |
| 80 | em.oltLosIndication(alarmInd.GetLosInd(), deviceID, raisedTs) |
| 81 | |
| 82 | case *oop.AlarmIndication_OnuAlarmInd: |
| 83 | log.Infow("Received onu alarm indication ", log.Fields{"alarm_ind": alarmInd}) |
| 84 | em.onuAlarmIndication(alarmInd.GetOnuAlarmInd(), deviceID, raisedTs) |
| 85 | |
| 86 | case *oop.AlarmIndication_DyingGaspInd: |
| 87 | log.Infow("Received dying gasp indication", log.Fields{"alarm_ind": alarmInd}) |
| 88 | em.onuDyingGaspIndication(alarmInd.GetDyingGaspInd(), deviceID, raisedTs) |
| 89 | |
| 90 | case *oop.AlarmIndication_OnuActivationFailInd: |
| 91 | log.Infow("Received onu activation fail indication ", log.Fields{"alarm_ind": alarmInd}) |
| 92 | em.onuActivationFailIndication(alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs) |
| 93 | |
| 94 | case *oop.AlarmIndication_OnuLossOmciInd: |
| 95 | log.Infow("Received onu loss omci indication ", log.Fields{"alarm_ind": alarmInd}) |
| 96 | em.onuLossOmciIndication(alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs) |
| 97 | |
| 98 | case *oop.AlarmIndication_OnuDriftOfWindowInd: |
| 99 | log.Infow("Received onu drift of window indication ", log.Fields{"alarm_ind": alarmInd}) |
| 100 | em.onuDriftOfWindowIndication(alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs) |
| 101 | |
| 102 | case *oop.AlarmIndication_OnuSignalDegradeInd: |
| 103 | log.Infow("Received onu signal degrade indication ", log.Fields{"alarm_ind": alarmInd}) |
| 104 | em.onuSignalDegradeIndication(alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs) |
| 105 | |
| 106 | case *oop.AlarmIndication_OnuSignalsFailInd: |
| 107 | log.Infow("Received onu signal fail indication ", log.Fields{"alarm_ind": alarmInd}) |
| 108 | em.onuSignalsFailIndication(alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs) |
| 109 | |
| 110 | case *oop.AlarmIndication_OnuProcessingErrorInd: |
| 111 | log.Infow("Received onu startup fail indication ", log.Fields{"alarm_ind": alarmInd}) |
| 112 | log.Infow("Not implemented yet", log.Fields{"alarm_ind": alarmInd}) |
| 113 | case *oop.AlarmIndication_OnuTiwiInd: |
| 114 | log.Infow("Received onu transmission warning indication ", log.Fields{"alarm_ind": alarmInd}) |
| 115 | log.Infow("Not implemented yet", log.Fields{"alarm_ind": "Onu-Transmission-indication"}) |
| 116 | default: |
| 117 | log.Errorw("Received unknown indication type", log.Fields{"alarm_ind": alarmInd}) |
| 118 | |
| 119 | } |
| 120 | } |
| 121 | |
Daniele Rossi | 051466a | 2019-07-26 13:39:37 +0000 | [diff] [blame] | 122 | // oltUpDownIndication handles Up and Down state of an OLT |
| 123 | func (em *OpenOltEventMgr) oltUpDownIndication(oltIndication *oop.OltIndication, deviceID string, raisedTs int64) { |
| 124 | var de voltha.DeviceEvent |
| 125 | context := make(map[string]string) |
| 126 | /* Populating event context */ |
| 127 | context["oper-state"] = string(oltIndication.OperState) |
| 128 | /* Populating device event body */ |
| 129 | de.Context = context |
| 130 | de.ResourceId = deviceID |
| 131 | if oltIndication.OperState == "down" { |
| 132 | de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT") |
| 133 | } else if oltIndication.OperState == "up" { |
| 134 | de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT") |
| 135 | } |
| 136 | /* Send event to KAFKA */ |
| 137 | if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil { |
| 138 | log.Errorw("Failed to send OLT event", log.Fields{"err": err}) |
| 139 | } |
| 140 | log.Infow("OLT UpDown event sent to KAFKA", log.Fields{}) |
| 141 | } |
| 142 | |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 143 | // OnuDiscoveryIndication is an exported method to handle ONU discovery event |
| 144 | func (em *OpenOltEventMgr) OnuDiscoveryIndication(onuDisc *oop.OnuDiscIndication, deviceID string, OnuID uint32, serialNumber string, raisedTs int64) { |
| 145 | var de voltha.DeviceEvent |
| 146 | context := make(map[string]string) |
| 147 | /* Populating event context */ |
| 148 | context["onu-id"] = string(OnuID) |
| 149 | context["intf-id"] = string(onuDisc.IntfId) |
| 150 | context["serial-number"] = serialNumber |
| 151 | /* Populating device event body */ |
| 152 | de.Context = context |
| 153 | de.ResourceId = deviceID |
| 154 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT") |
| 155 | /* Send event to KAFKA */ |
| 156 | if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil { |
| 157 | log.Errorw("Failed to send ONU discovery event", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId}) |
| 158 | } |
| 159 | log.Infow("ONU discovery event sent to KAFKA", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId}) |
| 160 | } |
| 161 | |
| 162 | func (em *OpenOltEventMgr) oltLosIndication(oltLos *oop.LosIndication, deviceID string, raisedTs int64) { |
| 163 | var de voltha.DeviceEvent |
| 164 | context := make(map[string]string) |
| 165 | /* Populating event context */ |
| 166 | context["intf-id"] = string(oltLos.IntfId) |
| 167 | /* Populating device event body */ |
| 168 | de.Context = context |
| 169 | de.ResourceId = deviceID |
| 170 | if oltLos.Status == "on" { |
| 171 | de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT") |
| 172 | } else { |
| 173 | de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT") |
| 174 | } |
| 175 | /* Send event to KAFKA */ |
| 176 | if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil { |
| 177 | log.Errorw("Failed to send OLT loss of signal event", log.Fields{"intf-id": oltLos.IntfId}) |
| 178 | } |
| 179 | log.Infow("OLT LOS event sent to KAFKA", log.Fields{"intf-id": oltLos.IntfId}) |
| 180 | } |
| 181 | |
| 182 | func (em *OpenOltEventMgr) onuDyingGaspIndication(dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) { |
| 183 | var de voltha.DeviceEvent |
| 184 | context := make(map[string]string) |
| 185 | /* Populating event context */ |
| 186 | context["intf-id"] = string(dgi.IntfId) |
| 187 | context["onu-id"] = string(dgi.OnuId) |
| 188 | /* Populating device event body */ |
| 189 | de.Context = context |
| 190 | de.ResourceId = deviceID |
| 191 | if dgi.Status == "on" { |
| 192 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "RAISE_EVENT") |
| 193 | } else { |
| 194 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "CLEAR_EVENT") |
| 195 | } |
| 196 | /* Send event to KAFKA */ |
| 197 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 198 | log.Errorw("Failed to send ONU Dying gasp event", log.Fields{"intf-id": dgi.IntfId, "onu-id": dgi.OnuId}) |
| 199 | } |
| 200 | log.Infow("ONU dying gasp event sent to KAFKA", log.Fields{"intf-id": dgi.IntfId}) |
| 201 | } |
| 202 | |
| 203 | func (em *OpenOltEventMgr) onuAlarmIndication(onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) { |
| 204 | var de voltha.DeviceEvent |
| 205 | context := make(map[string]string) |
| 206 | /* Populating event context */ |
| 207 | context["intf-id"] = string(onuAlarm.IntfId) |
| 208 | context["onu-id"] = string(onuAlarm.OnuId) |
| 209 | /* Populating device event body */ |
| 210 | de.Context = context |
| 211 | de.ResourceId = deviceID |
| 212 | if onuAlarm.LosStatus == "on" { |
| 213 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT") |
| 214 | } else if onuAlarm.LosStatus == "off" { |
| 215 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT") |
| 216 | } else if onuAlarm.LobStatus == "on" { |
| 217 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT") |
| 218 | } else if onuAlarm.LobStatus == "off" { |
| 219 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT") |
| 220 | } else if onuAlarm.LopcMissStatus == "on" { |
| 221 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT") |
| 222 | } else if onuAlarm.LopcMissStatus == "off" { |
| 223 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT") |
| 224 | } else if onuAlarm.LopcMicErrorStatus == "on" { |
| 225 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT") |
| 226 | } else if onuAlarm.LopcMicErrorStatus == "off" { |
| 227 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT") |
| 228 | } |
| 229 | /* Send event to KAFKA */ |
| 230 | if err := em.eventProxy.SendDeviceEvent(&de, communication, onu, raisedTs); err != nil { |
| 231 | log.Errorw("Failed to send ONU Los event", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId}) |
| 232 | } |
| 233 | log.Infow("ONU LOS event sent to KAFKA", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId}) |
| 234 | } |
| 235 | |
| 236 | func (em *OpenOltEventMgr) onuActivationFailIndication(oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) { |
| 237 | var de voltha.DeviceEvent |
| 238 | context := make(map[string]string) |
| 239 | /* Populating event context */ |
| 240 | context["intf-id"] = string(oaf.IntfId) |
| 241 | context["onu-id"] = string(oaf.OnuId) |
| 242 | /* Populating device event body */ |
| 243 | de.Context = context |
| 244 | de.ResourceId = deviceID |
| 245 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT") |
| 246 | /* Send event to KAFKA */ |
| 247 | if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil { |
| 248 | log.Errorw("Failed to send ONU activation failure event", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId}) |
| 249 | } |
| 250 | log.Infow("ONU activation failure event sent to KAFKA", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId}) |
| 251 | } |
| 252 | |
| 253 | func (em *OpenOltEventMgr) onuLossOmciIndication(onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) { |
| 254 | var de voltha.DeviceEvent |
| 255 | context := make(map[string]string) |
| 256 | /* Populating event context */ |
| 257 | context["intf-id"] = string(onuLossOmci.IntfId) |
| 258 | context["onu-id"] = string(onuLossOmci.OnuId) |
| 259 | /* Populating device event body */ |
| 260 | de.Context = context |
| 261 | de.ResourceId = deviceID |
| 262 | if onuLossOmci.Status == "on" { |
| 263 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT") |
| 264 | } else { |
| 265 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT") |
| 266 | } |
| 267 | /* Send event to KAFKA */ |
| 268 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 269 | log.Errorw("Failed to send ONU loss of OMCI channel event", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId}) |
| 270 | } |
| 271 | log.Infow("ONU loss of OMCI channel event sent to KAFKA", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId}) |
| 272 | } |
| 273 | |
| 274 | func (em *OpenOltEventMgr) onuDriftOfWindowIndication(onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) { |
| 275 | var de voltha.DeviceEvent |
| 276 | context := make(map[string]string) |
| 277 | /* Populating event context */ |
| 278 | context["intf-id"] = string(onuDriftWindow.IntfId) |
| 279 | context["onu-id"] = string(onuDriftWindow.OnuId) |
| 280 | context["drift"] = string(onuDriftWindow.OnuId) |
| 281 | context["new-eqd"] = string(onuDriftWindow.OnuId) |
| 282 | /* Populating device event body */ |
| 283 | de.Context = context |
| 284 | de.ResourceId = deviceID |
| 285 | if onuDriftWindow.Status == "on" { |
| 286 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT") |
| 287 | } else { |
| 288 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT") |
| 289 | } |
| 290 | /* Send event to KAFKA */ |
| 291 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 292 | log.Errorw("Failed to send ONU drift of window event", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId}) |
| 293 | } |
| 294 | log.Infow("ONU drift of window event sent to KAFKA", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId}) |
| 295 | } |
| 296 | |
| 297 | func (em *OpenOltEventMgr) onuSignalDegradeIndication(onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) { |
| 298 | var de voltha.DeviceEvent |
| 299 | context := make(map[string]string) |
| 300 | /* Populating event context */ |
| 301 | context["intf-id"] = string(onuSignalDegrade.IntfId) |
| 302 | context["onu-id"] = string(onuSignalDegrade.OnuId) |
| 303 | /* Populating device event body */ |
| 304 | de.Context = context |
| 305 | de.ResourceId = deviceID |
| 306 | if onuSignalDegrade.Status == "on" { |
| 307 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT") |
| 308 | } else { |
| 309 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT") |
| 310 | } |
| 311 | /* Send event to KAFKA */ |
| 312 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 313 | log.Errorw("Failed to send ONU signals degrade event", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId}) |
| 314 | } |
| 315 | log.Infow("ONU signal degrade event sent to KAFKA", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId}) |
| 316 | } |
| 317 | |
| 318 | func (em *OpenOltEventMgr) onuSignalsFailIndication(onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) { |
| 319 | var de voltha.DeviceEvent |
| 320 | context := make(map[string]string) |
| 321 | /* Populating event context */ |
| 322 | context["onu-id"] = string(onuSignalsFail.OnuId) |
| 323 | context["intf-id"] = string(onuSignalsFail.IntfId) |
| 324 | context["inverse-bit-error-rate"] = string(onuSignalsFail.InverseBitErrorRate) |
| 325 | /* Populating device event body */ |
| 326 | de.Context = context |
| 327 | de.ResourceId = deviceID |
| 328 | if onuSignalsFail.Status == "on" { |
| 329 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT") |
| 330 | } else { |
| 331 | de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT") |
| 332 | } |
| 333 | /* Send event to KAFKA */ |
| 334 | if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil { |
| 335 | log.Errorw("Failed to send ONU signals fail event", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId}) |
| 336 | } |
| 337 | log.Infow("ONU signals fail event sent to KAFKA", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId}) |
| 338 | } |