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