Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | // Package service provides constants. |
| 17 | package service |
| 18 | |
| 19 | const ( |
| 20 | errorCodeStartRange = 1000 |
| 21 | ) |
| 22 | |
| 23 | const ( |
| 24 | // VolthaErrorMessageFormat represents the format in which the Voltha accepts the errors. |
| 25 | VolthaErrorMessageFormat = "code = %d, desc = %s" |
| 26 | ) |
| 27 | |
| 28 | // ErrorCode is Enum of error type |
| 29 | type ErrorCode int |
| 30 | |
| 31 | //ErrorAction is Enum for error action |
| 32 | type ErrorAction int |
| 33 | |
| 34 | const ( |
| 35 | //ErrOk is returned when request is successful |
| 36 | ErrOk ErrorCode = 0 |
| 37 | //ErrInProgress is returned when operation is in progress |
| 38 | ErrInProgress ErrorCode = iota + errorCodeStartRange |
| 39 | //ErrInvalidParm is returned when parameter is wrong |
| 40 | ErrInvalidParm |
| 41 | //ErrResourceUnavailable is returned when no free resources are available |
| 42 | ErrResourceUnavailable |
| 43 | //ErrAlreadyExists is returned when entry already exists |
| 44 | ErrAlreadyExists |
| 45 | //ErrNotExists is returned when entry does not exists |
| 46 | ErrNotExists |
| 47 | //ErrInvalidOperation is returned when invalid operation is performed |
| 48 | ErrInvalidOperation |
| 49 | //ErrDeviceNotConnected is returned when there is no connection with the target system |
| 50 | ErrDeviceNotConnected |
| 51 | //ErrTimeout is returned when operation times out |
| 52 | ErrTimeout |
| 53 | //ErrResourceBusy is returned when resource is busy |
| 54 | ErrResourceBusy |
| 55 | //ErrInternal is returned when Errors happened internally |
| 56 | ErrInternal |
| 57 | //ErrIo is returned when there is I/O error |
| 58 | ErrIo |
| 59 | //ErrMandatoryParmIsMissing is returned when mandatory parameter is missing |
| 60 | ErrMandatoryParmIsMissing |
| 61 | //ErrBadState is returned when object is in bad state |
| 62 | ErrBadState |
| 63 | //ErrOnuInternal is returned when ONT internal failure occurs |
| 64 | ErrOnuInternal |
| 65 | //ErrElanNotCreated is returned when ELAN is not created |
| 66 | ErrElanNotCreated |
| 67 | //ErrOltInternal is returned when OLT internal failure occurs |
| 68 | ErrOltInternal |
| 69 | ) |
| 70 | |
| 71 | //ErrorCodeMap converts error code to error description string |
| 72 | var ErrorCodeMap = map[ErrorCode]string{ |
| 73 | ErrOk: "Success", |
| 74 | ErrInProgress: "Operation is in progress", |
| 75 | ErrInvalidParm: "Invalid parameter", |
| 76 | ErrResourceUnavailable: "No free resource available", |
| 77 | ErrAlreadyExists: "Entry already exists", |
| 78 | ErrNotExists: "Entry does not exists", |
| 79 | ErrInvalidOperation: "Invalid Operation", |
| 80 | ErrDeviceNotConnected: "No connection with the target system", |
| 81 | ErrTimeout: "Operation timed out", |
| 82 | ErrResourceBusy: "Resource Busy", |
| 83 | ErrInternal: "Internal Error", |
| 84 | ErrIo: "I/O Error", |
| 85 | ErrMandatoryParmIsMissing: "Mandatory parameter is missing", |
| 86 | ErrBadState: "Object is in bad state", |
| 87 | ErrOnuInternal: "ONT internal error", |
| 88 | ErrElanNotCreated: "ELAN not created", |
| 89 | ErrOltInternal: "OLT internal error", |
| 90 | } |
| 91 | |
| 92 | const ( |
| 93 | //Retry is returned if subservice reactivation is required |
| 94 | Retry ErrorAction = iota |
| 95 | //Quiet is returned if no action has to be taken |
| 96 | Quiet |
| 97 | //Deactivate is returned if subservice has to be deactivated |
| 98 | Deactivate |
| 99 | //Invalid is returned when invalid error is received from vgc |
| 100 | Invalid |
| 101 | ) |
| 102 | |
| 103 | //RetryErrorCodeMap consists of errors that requires service activation retry |
| 104 | var RetryErrorCodeMap = map[ErrorCode]ErrorAction{ |
| 105 | ErrOk: Quiet, |
| 106 | ErrInProgress: Deactivate, |
| 107 | ErrInvalidParm: Deactivate, |
| 108 | ErrResourceUnavailable: Deactivate, |
| 109 | ErrAlreadyExists: Quiet, |
| 110 | ErrNotExists: Quiet, |
| 111 | ErrInvalidOperation: Deactivate, |
| 112 | ErrDeviceNotConnected: Quiet, |
| 113 | ErrTimeout: Retry, |
| 114 | ErrResourceBusy: Retry, |
| 115 | ErrInternal: Deactivate, |
| 116 | ErrIo: Retry, |
| 117 | ErrMandatoryParmIsMissing: Deactivate, |
| 118 | ErrBadState: Deactivate, |
| 119 | ErrOnuInternal: Retry, |
| 120 | ErrElanNotCreated: Retry, |
| 121 | ErrOltInternal: Deactivate, |
| 122 | } |