Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [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 alarmsim |
| 18 | |
| 19 | import ( |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 20 | "fmt" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 21 | "github.com/opencord/bbsim/internal/bbsim/types" |
Anand S Katti | 86552f9 | 2020-03-03 21:56:32 +0530 | [diff] [blame] | 22 | "strconv" |
| 23 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 24 | "github.com/opencord/bbsim/internal/common" |
| 25 | |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 26 | "github.com/opencord/bbsim/api/bbsim" |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 27 | "github.com/opencord/voltha-protos/v4/go/openolt" |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
Kent Hagerman | 60d6230 | 2020-03-10 17:02:36 -0400 | [diff] [blame] | 30 | func AlarmNameToEnum(name string) (bbsim.AlarmType_Types, error) { |
| 31 | v, okay := common.ONUAlarms[name] |
Pragya Arya | 694ece0 | 2020-02-07 13:03:47 +0530 | [diff] [blame] | 32 | if !okay { |
Kent Hagerman | 60d6230 | 2020-03-10 17:02:36 -0400 | [diff] [blame] | 33 | return 0, fmt.Errorf("Unknown Alarm Name: %v", name) |
Pragya Arya | 694ece0 | 2020-02-07 13:03:47 +0530 | [diff] [blame] | 34 | } |
| 35 | |
Kent Hagerman | 60d6230 | 2020-03-10 17:02:36 -0400 | [diff] [blame] | 36 | return v, nil |
Pragya Arya | 694ece0 | 2020-02-07 13:03:47 +0530 | [diff] [blame] | 37 | } |
| 38 | |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 39 | // Find a key in the optional AlarmParameters, convert it to an integer, |
| 40 | // return 'def' if no key exists or it cannot be converted. |
| 41 | func 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 Katti | 86552f9 | 2020-03-03 21:56:32 +0530 | [diff] [blame] | 53 | // BuildOnuAlarmIndication function forms openolt alarmIndication as per ONUAlarmRequest |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 54 | func BuildOnuAlarmIndication(req *bbsim.ONUAlarmRequest, onuID uint32, ponPortID uint32) (*openolt.AlarmIndication, error) { |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 55 | var alarm *openolt.AlarmIndication |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 56 | var err error |
| 57 | |
Pragya Arya | 694ece0 | 2020-02-07 13:03:47 +0530 | [diff] [blame] | 58 | alarmType, err := AlarmNameToEnum(req.AlarmType) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | |
Kent Hagerman | 60d6230 | 2020-03-10 17:02:36 -0400 | [diff] [blame] | 63 | switch alarmType { |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 64 | case bbsim.AlarmType_DYING_GASP: |
| 65 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 66 | Data: &openolt.AlarmIndication_DyingGaspInd{DyingGaspInd: &openolt.DyingGaspIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 67 | Status: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 68 | OnuId: onuID, |
| 69 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 70 | }}, |
| 71 | } |
| 72 | case bbsim.AlarmType_ONU_STARTUP_FAILURE: |
| 73 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 74 | Data: &openolt.AlarmIndication_OnuStartupFailInd{OnuStartupFailInd: &openolt.OnuStartupFailureIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 75 | Status: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 76 | OnuId: onuID, |
| 77 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 78 | }}, |
| 79 | } |
| 80 | case bbsim.AlarmType_ONU_SIGNAL_DEGRADE: |
| 81 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 82 | Data: &openolt.AlarmIndication_OnuSignalDegradeInd{OnuSignalDegradeInd: &openolt.OnuSignalDegradeIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 83 | Status: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 84 | OnuId: onuID, |
| 85 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 86 | InverseBitErrorRate: uint32(extractInt(req.Parameters, "InverseBitErrorRate", 0)), |
| 87 | }}, |
| 88 | } |
Scott Baker | 8099ef8 | 2020-02-05 12:02:57 -0800 | [diff] [blame] | 89 | case bbsim.AlarmType_ONU_SIGNALS_FAILURE: |
| 90 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 91 | Data: &openolt.AlarmIndication_OnuSignalsFailInd{OnuSignalsFailInd: &openolt.OnuSignalsFailureIndication{ |
Scott Baker | 8099ef8 | 2020-02-05 12:02:57 -0800 | [diff] [blame] | 92 | Status: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 93 | OnuId: onuID, |
| 94 | IntfId: ponPortID, |
Scott Baker | 8099ef8 | 2020-02-05 12:02:57 -0800 | [diff] [blame] | 95 | InverseBitErrorRate: uint32(extractInt(req.Parameters, "InverseBitErrorRate", 0)), |
| 96 | }}, |
| 97 | } |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 98 | case bbsim.AlarmType_ONU_DRIFT_OF_WINDOW: |
| 99 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 100 | Data: &openolt.AlarmIndication_OnuDriftOfWindowInd{OnuDriftOfWindowInd: &openolt.OnuDriftOfWindowIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 101 | Status: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 102 | OnuId: onuID, |
| 103 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 104 | 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 Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 110 | Data: &openolt.AlarmIndication_OnuLossOmciInd{OnuLossOmciInd: &openolt.OnuLossOfOmciChannelIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 111 | Status: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 112 | OnuId: onuID, |
| 113 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 114 | }}, |
| 115 | } |
| 116 | case bbsim.AlarmType_ONU_TRANSMISSION_INTERFERENCE_WARNING: |
| 117 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 118 | Data: &openolt.AlarmIndication_OnuTiwiInd{OnuTiwiInd: &openolt.OnuTransmissionInterferenceWarning{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 119 | Status: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 120 | OnuId: onuID, |
| 121 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 122 | Drift: uint32(extractInt(req.Parameters, "Drift", 0)), |
| 123 | }}, |
| 124 | } |
| 125 | case bbsim.AlarmType_ONU_ACTIVATION_FAILURE: |
| 126 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 127 | Data: &openolt.AlarmIndication_OnuActivationFailInd{OnuActivationFailInd: &openolt.OnuActivationFailureIndication{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 128 | OnuId: onuID, |
| 129 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 130 | FailReason: uint32(extractInt(req.Parameters, "FailReason", 0)), |
| 131 | }}, |
| 132 | } |
| 133 | case bbsim.AlarmType_ONU_PROCESSING_ERROR: |
| 134 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 135 | Data: &openolt.AlarmIndication_OnuProcessingErrorInd{OnuProcessingErrorInd: &openolt.OnuProcessingErrorIndication{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 136 | OnuId: onuID, |
| 137 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 138 | }}, |
| 139 | } |
| 140 | case bbsim.AlarmType_ONU_LOSS_OF_KEY_SYNC_FAILURE: |
| 141 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 142 | Data: &openolt.AlarmIndication_OnuLossOfSyncFailInd{OnuLossOfSyncFailInd: &openolt.OnuLossOfKeySyncFailureIndication{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 143 | OnuId: onuID, |
| 144 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 145 | Status: req.Status, |
| 146 | }}, |
| 147 | } |
| 148 | case bbsim.AlarmType_ONU_ITU_PON_STATS: |
| 149 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 150 | Data: &openolt.AlarmIndication_OnuItuPonStatsInd{OnuItuPonStatsInd: &openolt.OnuItuPonStatsIndication{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 151 | OnuId: onuID, |
| 152 | IntfId: ponPortID, |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 153 | Stats: &openolt.OnuItuPonStatsIndication_RdiErrorInd{ |
| 154 | RdiErrorInd: &openolt.RdiErrorIndication{ |
| 155 | RdiErrorCount: uint64(extractInt(req.Parameters, "RdiErrors", 0)), |
| 156 | Status: req.Status, |
| 157 | }, |
| 158 | }, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 159 | }}, |
| 160 | } |
| 161 | case bbsim.AlarmType_ONU_ALARM_LOS: |
| 162 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 163 | Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 164 | LosStatus: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 165 | OnuId: onuID, |
| 166 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 167 | }}, |
| 168 | } |
| 169 | case bbsim.AlarmType_ONU_ALARM_LOB: |
| 170 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 171 | Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 172 | LobStatus: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 173 | OnuId: onuID, |
| 174 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 175 | }}, |
| 176 | } |
| 177 | case bbsim.AlarmType_ONU_ALARM_LOPC_MISS: |
| 178 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 179 | Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 180 | LopcMissStatus: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 181 | OnuId: onuID, |
| 182 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 183 | }}, |
| 184 | } |
| 185 | case bbsim.AlarmType_ONU_ALARM_LOPC_MIC_ERROR: |
| 186 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 187 | Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 188 | LopcMicErrorStatus: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 189 | OnuId: onuID, |
| 190 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 191 | }}, |
| 192 | } |
| 193 | case bbsim.AlarmType_ONU_ALARM_LOFI: |
| 194 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 195 | Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 196 | LofiStatus: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 197 | OnuId: onuID, |
| 198 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 199 | }}, |
| 200 | } |
| 201 | case bbsim.AlarmType_ONU_ALARM_LOAMI: |
| 202 | alarm = &openolt.AlarmIndication{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 203 | Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{ |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 204 | LoamiStatus: req.Status, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 205 | OnuId: onuID, |
| 206 | IntfId: ponPortID, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 207 | }}, |
| 208 | } |
| 209 | default: |
Kent Hagerman | 60d6230 | 2020-03-10 17:02:36 -0400 | [diff] [blame] | 210 | return nil, fmt.Errorf("Unknown ONU alarm type %v", req.AlarmType) |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | return alarm, nil |
| 214 | } |
| 215 | |
Anand S Katti | 86552f9 | 2020-03-03 21:56:32 +0530 | [diff] [blame] | 216 | // SimulateOnuAlarm accept request for Onu alarms and send proper alarmIndication to openolt stream |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 217 | func SimulateOnuAlarm(req *bbsim.ONUAlarmRequest, onuID uint32, ponPortID uint32, channel chan types.Message) error { |
| 218 | alarmIndication, err := BuildOnuAlarmIndication(req, onuID, ponPortID) |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 219 | if err != nil { |
| 220 | return err |
| 221 | } |
| 222 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 223 | msg := types.Message{ |
| 224 | Type: types.AlarmIndication, |
| 225 | Data: alarmIndication, |
Scott Baker | 41724b8 | 2020-01-21 19:54:53 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame^] | 228 | channel <- msg |
Anand S Katti | 86552f9 | 2020-03-03 21:56:32 +0530 | [diff] [blame] | 229 | |
| 230 | return nil |
| 231 | } |