blob: 4c74361a9f8862370a551b6a10cf6665ce20515d [file] [log] [blame]
Devmalya Paulfb990a52019-07-09 10:01:49 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// Package adaptercore provides APIs for the openOLT adapter
18package adaptercore
19
20import (
21 "fmt"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053022
Scott Baker51290152019-10-24 14:23:20 -070023 "github.com/opencord/voltha-lib-go/v2/pkg/adapters/adapterif"
24 "github.com/opencord/voltha-lib-go/v2/pkg/log"
Scott Bakerc6e54cb2019-11-04 09:31:25 -080025 oop "github.com/opencord/voltha-protos/v2/go/openolt"
26 "github.com/opencord/voltha-protos/v2/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040027)
28
29const (
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 Rossi051466a2019-07-26 13:39:37 +000036 oltIndicationDown = "OLT_DOWN_INDICATION"
Devmalya Paulfb990a52019-07-09 10:01:49 -040037 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
48const (
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
63type OpenOltEventMgr struct {
kdarapu381c6902019-07-31 18:23:16 +053064 eventProxy adapterif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040065 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -040066}
67
68// NewEventMgr is a Function to get a new event manager struct for the OpenOLT to process and publish OpenOLT event
Devmalya Paul90ca3012019-09-02 21:55:45 -040069func NewEventMgr(eventProxy adapterif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -040070 var em OpenOltEventMgr
71 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -040072 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -040073 return &em
74}
75
76// ProcessEvents is function to process and publish OpenOLT event
77func (em *OpenOltEventMgr) ProcessEvents(alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
78
79 switch alarmInd.Data.(type) {
80 case *oop.AlarmIndication_LosInd:
81 log.Infow("Received LOS indication", log.Fields{"alarm_ind": alarmInd})
82 em.oltLosIndication(alarmInd.GetLosInd(), deviceID, raisedTs)
83
84 case *oop.AlarmIndication_OnuAlarmInd:
85 log.Infow("Received onu alarm indication ", log.Fields{"alarm_ind": alarmInd})
86 em.onuAlarmIndication(alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
87
88 case *oop.AlarmIndication_DyingGaspInd:
89 log.Infow("Received dying gasp indication", log.Fields{"alarm_ind": alarmInd})
90 em.onuDyingGaspIndication(alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
91
92 case *oop.AlarmIndication_OnuActivationFailInd:
93 log.Infow("Received onu activation fail indication ", log.Fields{"alarm_ind": alarmInd})
94 em.onuActivationFailIndication(alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs)
95
96 case *oop.AlarmIndication_OnuLossOmciInd:
97 log.Infow("Received onu loss omci indication ", log.Fields{"alarm_ind": alarmInd})
98 em.onuLossOmciIndication(alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
99
100 case *oop.AlarmIndication_OnuDriftOfWindowInd:
101 log.Infow("Received onu drift of window indication ", log.Fields{"alarm_ind": alarmInd})
102 em.onuDriftOfWindowIndication(alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
103
104 case *oop.AlarmIndication_OnuSignalDegradeInd:
105 log.Infow("Received onu signal degrade indication ", log.Fields{"alarm_ind": alarmInd})
106 em.onuSignalDegradeIndication(alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
107
108 case *oop.AlarmIndication_OnuSignalsFailInd:
109 log.Infow("Received onu signal fail indication ", log.Fields{"alarm_ind": alarmInd})
110 em.onuSignalsFailIndication(alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
111
112 case *oop.AlarmIndication_OnuProcessingErrorInd:
113 log.Infow("Received onu startup fail indication ", log.Fields{"alarm_ind": alarmInd})
114 log.Infow("Not implemented yet", log.Fields{"alarm_ind": alarmInd})
115 case *oop.AlarmIndication_OnuTiwiInd:
116 log.Infow("Received onu transmission warning indication ", log.Fields{"alarm_ind": alarmInd})
117 log.Infow("Not implemented yet", log.Fields{"alarm_ind": "Onu-Transmission-indication"})
118 default:
119 log.Errorw("Received unknown indication type", log.Fields{"alarm_ind": alarmInd})
120
121 }
122}
123
Daniele Rossi051466a2019-07-26 13:39:37 +0000124// oltUpDownIndication handles Up and Down state of an OLT
125func (em *OpenOltEventMgr) oltUpDownIndication(oltIndication *oop.OltIndication, deviceID string, raisedTs int64) {
126 var de voltha.DeviceEvent
127 context := make(map[string]string)
128 /* Populating event context */
129 context["oper-state"] = string(oltIndication.OperState)
130 /* Populating device event body */
131 de.Context = context
132 de.ResourceId = deviceID
133 if oltIndication.OperState == "down" {
134 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
135 } else if oltIndication.OperState == "up" {
136 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
137 }
138 /* Send event to KAFKA */
139 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
140 log.Errorw("Failed to send OLT event", log.Fields{"err": err})
141 }
142 log.Infow("OLT UpDown event sent to KAFKA", log.Fields{})
143}
144
Devmalya Paulfb990a52019-07-09 10:01:49 -0400145// OnuDiscoveryIndication is an exported method to handle ONU discovery event
146func (em *OpenOltEventMgr) OnuDiscoveryIndication(onuDisc *oop.OnuDiscIndication, deviceID string, OnuID uint32, serialNumber string, raisedTs int64) {
147 var de voltha.DeviceEvent
148 context := make(map[string]string)
149 /* Populating event context */
150 context["onu-id"] = string(OnuID)
151 context["intf-id"] = string(onuDisc.IntfId)
152 context["serial-number"] = serialNumber
153 /* Populating device event body */
154 de.Context = context
155 de.ResourceId = deviceID
156 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
157 /* Send event to KAFKA */
158 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
159 log.Errorw("Failed to send ONU discovery event", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId})
160 }
161 log.Infow("ONU discovery event sent to KAFKA", log.Fields{"serial-number": serialNumber, "intf-id": onuDisc.IntfId})
162}
163
164func (em *OpenOltEventMgr) oltLosIndication(oltLos *oop.LosIndication, deviceID string, raisedTs int64) {
165 var de voltha.DeviceEvent
166 context := make(map[string]string)
167 /* Populating event context */
168 context["intf-id"] = string(oltLos.IntfId)
169 /* Populating device event body */
170 de.Context = context
171 de.ResourceId = deviceID
172 if oltLos.Status == "on" {
173 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
174 } else {
175 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
176 }
177 /* Send event to KAFKA */
178 if err := em.eventProxy.SendDeviceEvent(&de, communication, olt, raisedTs); err != nil {
179 log.Errorw("Failed to send OLT loss of signal event", log.Fields{"intf-id": oltLos.IntfId})
180 }
181 log.Infow("OLT LOS event sent to KAFKA", log.Fields{"intf-id": oltLos.IntfId})
182}
183
184func (em *OpenOltEventMgr) onuDyingGaspIndication(dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) {
185 var de voltha.DeviceEvent
Devmalya Paul90ca3012019-09-02 21:55:45 -0400186 var serialNumber string
Devmalya Paulfb990a52019-07-09 10:01:49 -0400187 context := make(map[string]string)
188 /* Populating event context */
Devmalya Paul90ca3012019-09-02 21:55:45 -0400189 serialNumber = ""
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530190 onu := em.handler.formOnuKey(dgi.IntfId, dgi.OnuId)
191 if onu, ok := em.handler.onus.Load(onu); ok {
192 serialNumber = onu.(*OnuDevice).serialNumber
Devmalya Paul90ca3012019-09-02 21:55:45 -0400193 }
194 context["serial-number"] = serialNumber
Devmalya Paulfb990a52019-07-09 10:01:49 -0400195 context["intf-id"] = string(dgi.IntfId)
196 context["onu-id"] = string(dgi.OnuId)
197 /* Populating device event body */
198 de.Context = context
199 de.ResourceId = deviceID
200 if dgi.Status == "on" {
201 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "RAISE_EVENT")
202 } else {
203 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "CLEAR_EVENT")
204 }
205 /* Send event to KAFKA */
206 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
207 log.Errorw("Failed to send ONU Dying gasp event", log.Fields{"intf-id": dgi.IntfId, "onu-id": dgi.OnuId})
208 }
209 log.Infow("ONU dying gasp event sent to KAFKA", log.Fields{"intf-id": dgi.IntfId})
210}
211
212func (em *OpenOltEventMgr) onuAlarmIndication(onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) {
213 var de voltha.DeviceEvent
214 context := make(map[string]string)
215 /* Populating event context */
216 context["intf-id"] = string(onuAlarm.IntfId)
217 context["onu-id"] = string(onuAlarm.OnuId)
218 /* Populating device event body */
219 de.Context = context
220 de.ResourceId = deviceID
221 if onuAlarm.LosStatus == "on" {
222 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
223 } else if onuAlarm.LosStatus == "off" {
224 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
225 } else if onuAlarm.LobStatus == "on" {
226 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
227 } else if onuAlarm.LobStatus == "off" {
228 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
229 } else if onuAlarm.LopcMissStatus == "on" {
230 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
231 } else if onuAlarm.LopcMissStatus == "off" {
232 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
233 } else if onuAlarm.LopcMicErrorStatus == "on" {
234 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
235 } else if onuAlarm.LopcMicErrorStatus == "off" {
236 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
237 }
238 /* Send event to KAFKA */
239 if err := em.eventProxy.SendDeviceEvent(&de, communication, onu, raisedTs); err != nil {
240 log.Errorw("Failed to send ONU Los event", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId})
241 }
242 log.Infow("ONU LOS event sent to KAFKA", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId})
243}
244
245func (em *OpenOltEventMgr) onuActivationFailIndication(oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) {
246 var de voltha.DeviceEvent
247 context := make(map[string]string)
248 /* Populating event context */
249 context["intf-id"] = string(oaf.IntfId)
250 context["onu-id"] = string(oaf.OnuId)
251 /* Populating device event body */
252 de.Context = context
253 de.ResourceId = deviceID
254 de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
255 /* Send event to KAFKA */
256 if err := em.eventProxy.SendDeviceEvent(&de, equipment, pon, raisedTs); err != nil {
257 log.Errorw("Failed to send ONU activation failure event", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId})
258 }
259 log.Infow("ONU activation failure event sent to KAFKA", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId})
260}
261
262func (em *OpenOltEventMgr) onuLossOmciIndication(onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) {
263 var de voltha.DeviceEvent
264 context := make(map[string]string)
265 /* Populating event context */
266 context["intf-id"] = string(onuLossOmci.IntfId)
267 context["onu-id"] = string(onuLossOmci.OnuId)
268 /* Populating device event body */
269 de.Context = context
270 de.ResourceId = deviceID
271 if onuLossOmci.Status == "on" {
272 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
273 } else {
274 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
275 }
276 /* Send event to KAFKA */
277 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
278 log.Errorw("Failed to send ONU loss of OMCI channel event", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId})
279 }
280 log.Infow("ONU loss of OMCI channel event sent to KAFKA", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId})
281}
282
283func (em *OpenOltEventMgr) onuDriftOfWindowIndication(onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) {
284 var de voltha.DeviceEvent
285 context := make(map[string]string)
286 /* Populating event context */
287 context["intf-id"] = string(onuDriftWindow.IntfId)
288 context["onu-id"] = string(onuDriftWindow.OnuId)
289 context["drift"] = string(onuDriftWindow.OnuId)
290 context["new-eqd"] = string(onuDriftWindow.OnuId)
291 /* Populating device event body */
292 de.Context = context
293 de.ResourceId = deviceID
294 if onuDriftWindow.Status == "on" {
295 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
296 } else {
297 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
298 }
299 /* Send event to KAFKA */
300 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
301 log.Errorw("Failed to send ONU drift of window event", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId})
302 }
303 log.Infow("ONU drift of window event sent to KAFKA", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId})
304}
305
306func (em *OpenOltEventMgr) onuSignalDegradeIndication(onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) {
307 var de voltha.DeviceEvent
308 context := make(map[string]string)
309 /* Populating event context */
310 context["intf-id"] = string(onuSignalDegrade.IntfId)
311 context["onu-id"] = string(onuSignalDegrade.OnuId)
312 /* Populating device event body */
313 de.Context = context
314 de.ResourceId = deviceID
315 if onuSignalDegrade.Status == "on" {
316 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
317 } else {
318 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
319 }
320 /* Send event to KAFKA */
321 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
322 log.Errorw("Failed to send ONU signals degrade event", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
323 }
324 log.Infow("ONU signal degrade event sent to KAFKA", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
325}
326
327func (em *OpenOltEventMgr) onuSignalsFailIndication(onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) {
328 var de voltha.DeviceEvent
329 context := make(map[string]string)
330 /* Populating event context */
331 context["onu-id"] = string(onuSignalsFail.OnuId)
332 context["intf-id"] = string(onuSignalsFail.IntfId)
333 context["inverse-bit-error-rate"] = string(onuSignalsFail.InverseBitErrorRate)
334 /* Populating device event body */
335 de.Context = context
336 de.ResourceId = deviceID
337 if onuSignalsFail.Status == "on" {
338 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
339 } else {
340 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
341 }
342 /* Send event to KAFKA */
343 if err := em.eventProxy.SendDeviceEvent(&de, communication, pon, raisedTs); err != nil {
344 log.Errorw("Failed to send ONU signals fail event", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
345 }
346 log.Infow("ONU signals fail event sent to KAFKA", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
347}