blob: e3d7e9379942a8eab60bca4bdaeb6baa38f0fc15 [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
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.
17package service
18
19const (
20 errorCodeStartRange = 1000
21)
22
23const (
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
29type ErrorCode int
30
vinokuma926cb3e2023-03-29 11:41:06 +053031// ErrorAction is Enum for error action
Naveen Sampath04696f72022-06-13 15:19:14 +053032type ErrorAction int
33
34const (
vinokuma926cb3e2023-03-29 11:41:06 +053035 // ErrOk is returned when request is successful
Naveen Sampath04696f72022-06-13 15:19:14 +053036 ErrOk ErrorCode = 0
vinokuma926cb3e2023-03-29 11:41:06 +053037 // ErrInProgress is returned when operation is in progress
Naveen Sampath04696f72022-06-13 15:19:14 +053038 ErrInProgress ErrorCode = iota + errorCodeStartRange
vinokuma926cb3e2023-03-29 11:41:06 +053039 // ErrInvalidParm is returned when parameter is wrong
Naveen Sampath04696f72022-06-13 15:19:14 +053040 ErrInvalidParm
vinokuma926cb3e2023-03-29 11:41:06 +053041 // ErrResourceUnavailable is returned when no free resources are available
Naveen Sampath04696f72022-06-13 15:19:14 +053042 ErrResourceUnavailable
vinokuma926cb3e2023-03-29 11:41:06 +053043 // ErrAlreadyExists is returned when entry already exists
Naveen Sampath04696f72022-06-13 15:19:14 +053044 ErrAlreadyExists
vinokuma926cb3e2023-03-29 11:41:06 +053045 // ErrNotExists is returned when entry does not exists
Naveen Sampath04696f72022-06-13 15:19:14 +053046 ErrNotExists
vinokuma926cb3e2023-03-29 11:41:06 +053047 // ErrInvalidOperation is returned when invalid operation is performed
Naveen Sampath04696f72022-06-13 15:19:14 +053048 ErrInvalidOperation
vinokuma926cb3e2023-03-29 11:41:06 +053049 // ErrDeviceNotConnected is returned when there is no connection with the target system
Naveen Sampath04696f72022-06-13 15:19:14 +053050 ErrDeviceNotConnected
vinokuma926cb3e2023-03-29 11:41:06 +053051 // ErrTimeout is returned when operation times out
Naveen Sampath04696f72022-06-13 15:19:14 +053052 ErrTimeout
vinokuma926cb3e2023-03-29 11:41:06 +053053 // ErrResourceBusy is returned when resource is busy
Naveen Sampath04696f72022-06-13 15:19:14 +053054 ErrResourceBusy
vinokuma926cb3e2023-03-29 11:41:06 +053055 // ErrInternal is returned when Errors happened internally
Naveen Sampath04696f72022-06-13 15:19:14 +053056 ErrInternal
vinokuma926cb3e2023-03-29 11:41:06 +053057 // ErrIo is returned when there is I/O error
Naveen Sampath04696f72022-06-13 15:19:14 +053058 ErrIo
vinokuma926cb3e2023-03-29 11:41:06 +053059 // ErrMandatoryParmIsMissing is returned when mandatory parameter is missing
Naveen Sampath04696f72022-06-13 15:19:14 +053060 ErrMandatoryParmIsMissing
vinokuma926cb3e2023-03-29 11:41:06 +053061 // ErrBadState is returned when object is in bad state
Naveen Sampath04696f72022-06-13 15:19:14 +053062 ErrBadState
vinokuma926cb3e2023-03-29 11:41:06 +053063 // ErrOnuInternal is returned when ONT internal failure occurs
Naveen Sampath04696f72022-06-13 15:19:14 +053064 ErrOnuInternal
vinokuma926cb3e2023-03-29 11:41:06 +053065 // ErrElanNotCreated is returned when ELAN is not created
Naveen Sampath04696f72022-06-13 15:19:14 +053066 ErrElanNotCreated
vinokuma926cb3e2023-03-29 11:41:06 +053067 // ErrOltInternal is returned when OLT internal failure occurs
Naveen Sampath04696f72022-06-13 15:19:14 +053068 ErrOltInternal
69)
70
vinokuma926cb3e2023-03-29 11:41:06 +053071// ErrorCodeMap converts error code to error description string
Naveen Sampath04696f72022-06-13 15:19:14 +053072var 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
92const (
vinokuma926cb3e2023-03-29 11:41:06 +053093 // Retry is returned if subservice reactivation is required
Naveen Sampath04696f72022-06-13 15:19:14 +053094 Retry ErrorAction = iota
vinokuma926cb3e2023-03-29 11:41:06 +053095 // Quiet is returned if no action has to be taken
Naveen Sampath04696f72022-06-13 15:19:14 +053096 Quiet
vinokuma926cb3e2023-03-29 11:41:06 +053097 // Deactivate is returned if subservice has to be deactivated
Naveen Sampath04696f72022-06-13 15:19:14 +053098 Deactivate
vinokuma926cb3e2023-03-29 11:41:06 +053099 // Invalid is returned when invalid error is received from vgc
Naveen Sampath04696f72022-06-13 15:19:14 +0530100 Invalid
101)
102
vinokuma926cb3e2023-03-29 11:41:06 +0530103// RetryErrorCodeMap consists of errors that requires service activation retry
Naveen Sampath04696f72022-06-13 15:19:14 +0530104var 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}