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