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 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 31 | // ErrorAction is Enum for error action |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 32 | type ErrorAction int |
| 33 | |
| 34 | const ( |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 35 | // ErrOk is returned when request is successful |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 36 | ErrOk ErrorCode = 0 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 37 | // ErrInProgress is returned when operation is in progress |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 38 | ErrInProgress ErrorCode = iota + errorCodeStartRange |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 39 | // ErrInvalidParm is returned when parameter is wrong |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 40 | ErrInvalidParm |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 41 | // ErrResourceUnavailable is returned when no free resources are available |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 42 | ErrResourceUnavailable |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 43 | // ErrAlreadyExists is returned when entry already exists |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 44 | ErrAlreadyExists |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 45 | // ErrNotExists is returned when entry does not exists |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 46 | ErrNotExists |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 47 | // ErrInvalidOperation is returned when invalid operation is performed |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 48 | ErrInvalidOperation |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 49 | // ErrDeviceNotConnected is returned when there is no connection with the target system |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 50 | ErrDeviceNotConnected |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 51 | // ErrTimeout is returned when operation times out |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 52 | ErrTimeout |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 53 | // ErrResourceBusy is returned when resource is busy |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 54 | ErrResourceBusy |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 55 | // ErrInternal is returned when Errors happened internally |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 56 | ErrInternal |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 57 | // ErrIo is returned when there is I/O error |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 58 | ErrIo |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 59 | // ErrMandatoryParmIsMissing is returned when mandatory parameter is missing |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 60 | ErrMandatoryParmIsMissing |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 61 | // ErrBadState is returned when object is in bad state |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 62 | ErrBadState |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 63 | // ErrOnuInternal is returned when ONT internal failure occurs |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 64 | ErrOnuInternal |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 65 | // ErrElanNotCreated is returned when ELAN is not created |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 66 | ErrElanNotCreated |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 67 | // ErrOltInternal is returned when OLT internal failure occurs |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 68 | ErrOltInternal |
| 69 | ) |
| 70 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 71 | // ErrorCodeMap converts error code to error description string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 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 ( |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 93 | // Retry is returned if subservice reactivation is required |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 94 | Retry ErrorAction = iota |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 95 | // Quiet is returned if no action has to be taken |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 96 | Quiet |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 97 | // Deactivate is returned if subservice has to be deactivated |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 98 | Deactivate |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 99 | // Invalid is returned when invalid error is received from vgc |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 100 | Invalid |
| 101 | ) |
| 102 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 103 | // RetryErrorCodeMap consists of errors that requires service activation retry |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 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 | } |