blob: 8bf369ec3ce8974a4ec30958bf75202b405dede9 [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
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 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14/*
15 * NOTE: This file was generated, manual edits will be overwritten!
16 *
17 * Generated by 'goCodeGenerator.py':
18 * https://github.com/cboling/OMCI-parser/README.md
19 */
20package generated
21
22import (
23 "errors"
24 "fmt"
25)
26
27// Custom Go Error messages for common OMCI errors
28//
29// Response Status code related errors
30type OmciErrors interface {
31 Error() string
32 StatusCode() Results
33 GetError() error
34}
35
36type OmciError struct {
37 err string
38 statusCode Results
39}
40
41func (e *OmciError) GetError() error {
42 return errors.New(e.err)
43}
44
45func (e *OmciError) Error() string {
46 return e.err
47}
48
49func (e *OmciError) StatusCode() Results {
50 return e.statusCode
51}
52
53func NewOmciError(text string, status Results) OmciErrors {
54 if status == Success {
55 panic("Do not use OmciError to convey successful results")
56 }
57 return &OmciError{
58 err: text,
59 statusCode: status,
60 }
61}
62
63type OmciNonStatusError struct {
64 OmciError
65}
66
67// NewNonStatusError is for processing errors that do not involve
68// frame processing status & results
69func NewNonStatusError(args ...interface{}) OmciErrors {
70 defaultValue := "command processing error"
71 return &OmciProcessingError{
72 OmciError: OmciError{
73 err: genMessage(defaultValue, args...),
74 },
75 }
76}
77
78type OmciProcessingError struct {
79 OmciError
80}
81
82// NewProcessingError means the command processing failed at the ONU
83// for reasons not described by one of the more specific error codes.
84func NewProcessingError(args ...interface{}) OmciErrors {
85 defaultValue := "command processing error"
86 return &OmciProcessingError{
87 OmciError: OmciError{
88 err: genMessage(defaultValue, args...),
89 statusCode: ProcessingError,
90 },
91 }
92}
93
94type NotSupportedError struct {
95 OmciError
96}
97
98// NewNotSupportedError means that the message type indicated in byte 3 is
99// not supported by the ONU.
100func NewNotSupportedError(args ...interface{}) OmciErrors {
101 defaultValue := "command not supported"
102 return &NotSupportedError{
103 OmciError: OmciError{
104 err: genMessage(defaultValue, args...),
105 statusCode: NotSupported,
106 },
107 }
108}
109
110type ParamError struct {
111 OmciError
112 FailureMask uint16
113}
114
115// NewParameterError means that the command message received by the
116// ONU was errored. It would be appropriate if an attribute mask
117// were out of range, for example. In practice, this result code is
118// frequently used interchangeably with code 1001. However, the
119// optional attribute and attribute execution masks in the reply
120// messages are only defined for code 1001.
121func NewParameterError(mask uint16, args ...interface{}) OmciErrors {
122 defaultValue := "parameter error"
123 return &ParamError{
124 OmciError: OmciError{
125 err: genMessage(defaultValue, args...),
126 statusCode: ParameterError,
127 },
128 FailureMask: mask,
129 }
130}
131
132type UnknownEntityError struct {
133 OmciError
134}
135
136// NewUnknownEntityError This result means that the managed entity class
137// (bytes 5..6) is not supported by the ONU.
138func NewUnknownEntityError(args ...interface{}) OmciErrors {
139 defaultValue := "unknown managed entity"
140 return &UnknownEntityError{
141 OmciError: OmciError{
142 err: genMessage(defaultValue, args...),
143 statusCode: UnknownEntity,
144 },
145 }
146}
147
148type UnknownInstanceError struct {
149 OmciError
150}
151
152// NewUnknownInstanceError means that the managed entity instance (bytes 7..8)
153// does not exist in the ONU.
154func NewUnknownInstanceError(args ...interface{}) OmciErrors {
155 defaultValue := "unknown managed entity instance"
156 return &UnknownInstanceError{
157 OmciError: OmciError{
158 err: genMessage(defaultValue, args...),
159 statusCode: UnknownInstance,
160 },
161 }
162}
163
164type DeviceBusyError struct {
165 OmciError
166}
167
168// NewDeviceBusyError means that the command could not be processed due
169// to process-related congestion at the ONU. This result code may
170// also be used as a pause indication to the OLT while the ONU
171// conducts a time-consuming operation such as storage of a
172// software image into non-volatile memory.
173func NewDeviceBusyError(args ...interface{}) OmciErrors {
174 defaultValue := "device busy"
175 return &DeviceBusyError{
176 OmciError: OmciError{
177 err: genMessage(defaultValue, args...),
178 statusCode: DeviceBusy,
179 },
180 }
181}
182
183type InstanceExistsError struct {
184 OmciError
185}
186
187// NewInstanceExistsError
188func NewInstanceExistsError(args ...interface{}) OmciErrors {
189 defaultValue := "instance exists"
190 return &InstanceExistsError{
191 OmciError: OmciError{
192 err: genMessage(defaultValue, args...),
193 statusCode: InstanceExists,
194 },
195 }
196}
197
198type AttributeFailureError struct {
199 OmciError
200}
201
202// NewAttributeFailureError means that the ONU already has a managed entity
203// instance that corresponds to the one the OLT is attempting to create.
204func NewAttributeFailureError(args ...interface{}) OmciErrors {
205 defaultValue := "attribute(s) failed or unknown"
206 return &AttributeFailureError{
207 OmciError: OmciError{
208 err: genMessage(defaultValue, args...),
209 statusCode: AttributeFailure,
210 },
211 }
212}
213
214type MessageTruncatedError struct {
215 OmciError
216}
217
218// NewAttributeFailureError means that the ONU already has a managed entity
219// instance that corresponds to the one the OLT is attempting to create.
220func NewMessageTruncatedError(args ...interface{}) OmciErrors {
221 defaultValue := "out-of-space. Cannot fit attribute into message"
222 return &MessageTruncatedError{
223 OmciError: OmciError{
224 err: genMessage(defaultValue, args...),
225 statusCode: ProcessingError,
226 },
227 }
228}
229
230func genMessage(defaultValue string, args ...interface{}) string {
231 switch len(args) {
232 case 0:
233 return defaultValue
234
235 case 1:
236 switch first := args[0].(type) {
237 case string:
238 // Assume a simple, pre-formatted string
239 return args[0].(string)
240
241 case func() string:
242 // Assume a closure with no other arguments used
243 return first()
244
245 default:
246 panic("Unsupported parameter type")
247 }
248 }
249 return fmt.Sprintf(args[0].(string), args[1:]...)
250}