blob: 6c6a290db1243f8d911e698ee1cbb62970427ab9 [file] [log] [blame]
Scott Baker41724b82020-01-21 19:54:53 -08001/*
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
17package alarmsim
18
19import (
Scott Baker41724b82020-01-21 19:54:53 -080020 "fmt"
Matteo Scandolof9d43412021-01-12 11:11:34 -080021 "github.com/opencord/bbsim/internal/bbsim/types"
Anand S Katti86552f92020-03-03 21:56:32 +053022 "strconv"
23
Shrey Baid688b4242020-07-10 20:40:10 +053024 "github.com/opencord/bbsim/internal/common"
25
Scott Baker41724b82020-01-21 19:54:53 -080026 "github.com/opencord/bbsim/api/bbsim"
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070027 "github.com/opencord/voltha-protos/v4/go/openolt"
Scott Baker41724b82020-01-21 19:54:53 -080028)
29
Kent Hagerman60d62302020-03-10 17:02:36 -040030func AlarmNameToEnum(name string) (bbsim.AlarmType_Types, error) {
31 v, okay := common.ONUAlarms[name]
Pragya Arya694ece02020-02-07 13:03:47 +053032 if !okay {
Kent Hagerman60d62302020-03-10 17:02:36 -040033 return 0, fmt.Errorf("Unknown Alarm Name: %v", name)
Pragya Arya694ece02020-02-07 13:03:47 +053034 }
35
Kent Hagerman60d62302020-03-10 17:02:36 -040036 return v, nil
Pragya Arya694ece02020-02-07 13:03:47 +053037}
38
Scott Baker41724b82020-01-21 19:54:53 -080039// Find a key in the optional AlarmParameters, convert it to an integer,
40// return 'def' if no key exists or it cannot be converted.
41func extractInt(params []*bbsim.AlarmParameter, name string, def int) int {
42 for _, kv := range params {
43 if kv.Key == name {
44 i, err := strconv.Atoi(kv.Value)
45 if err == nil {
46 return i
47 }
48 }
49 }
50 return def
51}
52
Anand S Katti86552f92020-03-03 21:56:32 +053053// BuildOnuAlarmIndication function forms openolt alarmIndication as per ONUAlarmRequest
Matteo Scandolof9d43412021-01-12 11:11:34 -080054func BuildOnuAlarmIndication(req *bbsim.ONUAlarmRequest, onuID uint32, ponPortID uint32) (*openolt.AlarmIndication, error) {
Scott Baker41724b82020-01-21 19:54:53 -080055 var alarm *openolt.AlarmIndication
Scott Baker41724b82020-01-21 19:54:53 -080056 var err error
57
Pragya Arya694ece02020-02-07 13:03:47 +053058 alarmType, err := AlarmNameToEnum(req.AlarmType)
59 if err != nil {
60 return nil, err
61 }
62
Kent Hagerman60d62302020-03-10 17:02:36 -040063 switch alarmType {
Scott Baker41724b82020-01-21 19:54:53 -080064 case bbsim.AlarmType_DYING_GASP:
65 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +053066 Data: &openolt.AlarmIndication_DyingGaspInd{DyingGaspInd: &openolt.DyingGaspIndication{
Scott Baker41724b82020-01-21 19:54:53 -080067 Status: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -080068 OnuId: onuID,
69 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -080070 }},
71 }
72 case bbsim.AlarmType_ONU_STARTUP_FAILURE:
73 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +053074 Data: &openolt.AlarmIndication_OnuStartupFailInd{OnuStartupFailInd: &openolt.OnuStartupFailureIndication{
Scott Baker41724b82020-01-21 19:54:53 -080075 Status: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -080076 OnuId: onuID,
77 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -080078 }},
79 }
80 case bbsim.AlarmType_ONU_SIGNAL_DEGRADE:
81 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +053082 Data: &openolt.AlarmIndication_OnuSignalDegradeInd{OnuSignalDegradeInd: &openolt.OnuSignalDegradeIndication{
Scott Baker41724b82020-01-21 19:54:53 -080083 Status: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -080084 OnuId: onuID,
85 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -080086 InverseBitErrorRate: uint32(extractInt(req.Parameters, "InverseBitErrorRate", 0)),
87 }},
88 }
Scott Baker8099ef82020-02-05 12:02:57 -080089 case bbsim.AlarmType_ONU_SIGNALS_FAILURE:
90 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +053091 Data: &openolt.AlarmIndication_OnuSignalsFailInd{OnuSignalsFailInd: &openolt.OnuSignalsFailureIndication{
Scott Baker8099ef82020-02-05 12:02:57 -080092 Status: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -080093 OnuId: onuID,
94 IntfId: ponPortID,
Scott Baker8099ef82020-02-05 12:02:57 -080095 InverseBitErrorRate: uint32(extractInt(req.Parameters, "InverseBitErrorRate", 0)),
96 }},
97 }
Scott Baker41724b82020-01-21 19:54:53 -080098 case bbsim.AlarmType_ONU_DRIFT_OF_WINDOW:
99 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530100 Data: &openolt.AlarmIndication_OnuDriftOfWindowInd{OnuDriftOfWindowInd: &openolt.OnuDriftOfWindowIndication{
Scott Baker41724b82020-01-21 19:54:53 -0800101 Status: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800102 OnuId: onuID,
103 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800104 Drift: uint32(extractInt(req.Parameters, "Drift", 0)),
105 NewEqd: uint32(extractInt(req.Parameters, "NewEqd", 0)),
106 }},
107 }
108 case bbsim.AlarmType_ONU_LOSS_OF_OMCI_CHANNEL:
109 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530110 Data: &openolt.AlarmIndication_OnuLossOmciInd{OnuLossOmciInd: &openolt.OnuLossOfOmciChannelIndication{
Scott Baker41724b82020-01-21 19:54:53 -0800111 Status: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800112 OnuId: onuID,
113 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800114 }},
115 }
116 case bbsim.AlarmType_ONU_TRANSMISSION_INTERFERENCE_WARNING:
117 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530118 Data: &openolt.AlarmIndication_OnuTiwiInd{OnuTiwiInd: &openolt.OnuTransmissionInterferenceWarning{
Scott Baker41724b82020-01-21 19:54:53 -0800119 Status: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800120 OnuId: onuID,
121 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800122 Drift: uint32(extractInt(req.Parameters, "Drift", 0)),
123 }},
124 }
125 case bbsim.AlarmType_ONU_ACTIVATION_FAILURE:
126 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530127 Data: &openolt.AlarmIndication_OnuActivationFailInd{OnuActivationFailInd: &openolt.OnuActivationFailureIndication{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800128 OnuId: onuID,
129 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800130 FailReason: uint32(extractInt(req.Parameters, "FailReason", 0)),
131 }},
132 }
133 case bbsim.AlarmType_ONU_PROCESSING_ERROR:
134 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530135 Data: &openolt.AlarmIndication_OnuProcessingErrorInd{OnuProcessingErrorInd: &openolt.OnuProcessingErrorIndication{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800136 OnuId: onuID,
137 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800138 }},
139 }
140 case bbsim.AlarmType_ONU_LOSS_OF_KEY_SYNC_FAILURE:
141 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530142 Data: &openolt.AlarmIndication_OnuLossOfSyncFailInd{OnuLossOfSyncFailInd: &openolt.OnuLossOfKeySyncFailureIndication{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800143 OnuId: onuID,
144 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800145 Status: req.Status,
146 }},
147 }
148 case bbsim.AlarmType_ONU_ITU_PON_STATS:
149 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530150 Data: &openolt.AlarmIndication_OnuItuPonStatsInd{OnuItuPonStatsInd: &openolt.OnuItuPonStatsIndication{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800151 OnuId: onuID,
152 IntfId: ponPortID,
Matteo Scandolo618a6582020-09-09 12:21:29 -0700153 Stats: &openolt.OnuItuPonStatsIndication_RdiErrorInd{
154 RdiErrorInd: &openolt.RdiErrorIndication{
155 RdiErrorCount: uint64(extractInt(req.Parameters, "RdiErrors", 0)),
156 Status: req.Status,
157 },
158 },
Scott Baker41724b82020-01-21 19:54:53 -0800159 }},
160 }
161 case bbsim.AlarmType_ONU_ALARM_LOS:
162 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530163 Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
Scott Baker41724b82020-01-21 19:54:53 -0800164 LosStatus: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800165 OnuId: onuID,
166 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800167 }},
168 }
169 case bbsim.AlarmType_ONU_ALARM_LOB:
170 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530171 Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
Scott Baker41724b82020-01-21 19:54:53 -0800172 LobStatus: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800173 OnuId: onuID,
174 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800175 }},
176 }
177 case bbsim.AlarmType_ONU_ALARM_LOPC_MISS:
178 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530179 Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
Scott Baker41724b82020-01-21 19:54:53 -0800180 LopcMissStatus: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800181 OnuId: onuID,
182 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800183 }},
184 }
185 case bbsim.AlarmType_ONU_ALARM_LOPC_MIC_ERROR:
186 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530187 Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
Scott Baker41724b82020-01-21 19:54:53 -0800188 LopcMicErrorStatus: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800189 OnuId: onuID,
190 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800191 }},
192 }
193 case bbsim.AlarmType_ONU_ALARM_LOFI:
194 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530195 Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
Scott Baker41724b82020-01-21 19:54:53 -0800196 LofiStatus: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800197 OnuId: onuID,
198 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800199 }},
200 }
201 case bbsim.AlarmType_ONU_ALARM_LOAMI:
202 alarm = &openolt.AlarmIndication{
Shrey Baid688b4242020-07-10 20:40:10 +0530203 Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
Scott Baker41724b82020-01-21 19:54:53 -0800204 LoamiStatus: req.Status,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800205 OnuId: onuID,
206 IntfId: ponPortID,
Scott Baker41724b82020-01-21 19:54:53 -0800207 }},
208 }
209 default:
Kent Hagerman60d62302020-03-10 17:02:36 -0400210 return nil, fmt.Errorf("Unknown ONU alarm type %v", req.AlarmType)
Scott Baker41724b82020-01-21 19:54:53 -0800211 }
212
213 return alarm, nil
214}
215
Anand S Katti86552f92020-03-03 21:56:32 +0530216// SimulateOnuAlarm accept request for Onu alarms and send proper alarmIndication to openolt stream
Matteo Scandolof9d43412021-01-12 11:11:34 -0800217func SimulateOnuAlarm(req *bbsim.ONUAlarmRequest, onuID uint32, ponPortID uint32, channel chan types.Message) error {
218 alarmIndication, err := BuildOnuAlarmIndication(req, onuID, ponPortID)
Scott Baker41724b82020-01-21 19:54:53 -0800219 if err != nil {
220 return err
221 }
222
Matteo Scandolof9d43412021-01-12 11:11:34 -0800223 msg := types.Message{
224 Type: types.AlarmIndication,
225 Data: alarmIndication,
Scott Baker41724b82020-01-21 19:54:53 -0800226 }
227
Matteo Scandolof9d43412021-01-12 11:11:34 -0800228 channel <- msg
Anand S Katti86552f92020-03-03 21:56:32 +0530229
230 return nil
231}