blob: 2631a42fb809b71ea9d262fd33986ef711bb37d6 [file] [log] [blame]
Chip Boling6e27b352020-02-14 09:10:01 -06001/*
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 */
20
21package generated
22
23import (
24 "errors"
25 "fmt"
26)
27
28// Custom Go Error messages for common OMCI errors
29//
30// Response Status code related errors
31type OmciErrors interface {
32 Error() string
33 StatusCode() Results
34 GetError() error
35 GetFailureMask() uint16
36 GetUnsupporteMask() uint16
37}
38
39type OmciError struct {
40 err string
41 statusCode Results
42 failureMask uint16
43 unsupportedMask uint16
44}
45
46func (e *OmciError) GetError() error {
47 if e.statusCode == Success {
48 return nil
49 }
50 return errors.New(e.err)
51}
52
53func (e *OmciError) Error() string {
54 return e.err
55}
56
57func (e *OmciError) StatusCode() Results {
58 return e.statusCode
59}
60
61func (e *OmciError) GetFailureMask() uint16 {
62 return e.failureMask
63}
64
65func (e *OmciError) GetUnsupporteMask() uint16 {
66 return e.unsupportedMask
67}
68
69// NewOmciSuccess is used to convey a successful request. For Set/Get responses,
70// this indicates that all attributes were successfully set/retrieved.
71//
72// For Set/Get requests that have unsupported/failed attributes (code 1001), use the
73// NewAttributeFailureError() function to convey the proper status (AttributeFailure).
74//
75// For Create requests that have parameter errors (code 0011), use the NewParameterError()
76// function to signal which attributes were in error
77func NewOmciSuccess() OmciErrors {
78 return &OmciError{
79 statusCode: Success,
80 }
81}
82
83// NewNonStatusError is for processing errors that do not involve
84// frame processing status & results
85func NewNonStatusError(args ...interface{}) OmciErrors {
86 defaultValue := "command processing error"
87 return &OmciProcessingError{
88 OmciError: OmciError{
89 err: genMessage(defaultValue, args...),
90 },
91 }
92}
93
94type OmciProcessingError struct {
95 OmciError
96}
97
98// NewProcessingError means the command processing failed at the ONU
99// for reasons not described by one of the more specific error codes.
100func NewProcessingError(args ...interface{}) OmciErrors {
101 defaultValue := "command processing error"
102 return &OmciProcessingError{
103 OmciError: OmciError{
104 err: genMessage(defaultValue, args...),
105 statusCode: ProcessingError,
106 },
107 }
108}
109
110// NotSupportedError means that the message type indicated in byte 3 is
111// not supported by the ONU.
112type NotSupportedError struct {
113 OmciError
114}
115
116// NewNotSupportedError creates a NotSupportedError
117func NewNotSupportedError(args ...interface{}) OmciErrors {
118 defaultValue := "command not supported"
119 return &NotSupportedError{
120 OmciError: OmciError{
121 err: genMessage(defaultValue, args...),
122 statusCode: NotSupported,
123 },
124 }
125}
126
127// ParamError means that the command message received by the
128// ONU was errored. It would be appropriate if an attribute mask
129// were out of range, for example. In practice, this result code is
130// frequently used interchangeably with code 1001. However, the
131// optional attribute and attribute execution masks in the reply
132// messages are only defined for code 1001.
133type ParamError struct {
134 OmciError
135}
136
137// NewParameterError creates a ParamError
138//
139// For Set/Get requests that have unsupported/failed attributes (code 1001), use the
140// NewAttributeFailureError() function to convey the proper status (AttributeFailure).
141func NewParameterError(mask uint16, args ...interface{}) OmciErrors {
142 if mask == 0 {
143 panic("invalid attribute mask specified")
144 }
145 defaultValue := "parameter error"
146 err := &ParamError{
147 OmciError: OmciError{
148 err: genMessage(defaultValue, args...),
149 statusCode: ParameterError,
150 failureMask: mask,
151 },
152 }
153 return err
154}
155
156// UnknownEntityError means that the managed entity class
157// (bytes 5..6) is not supported by the ONU.
158type UnknownEntityError struct {
159 OmciError
160}
161
162// NewUnknownEntityError creates an UnknownEntityError
163func NewUnknownEntityError(args ...interface{}) OmciErrors {
164 defaultValue := "unknown managed entity"
165 return &UnknownEntityError{
166 OmciError: OmciError{
167 err: genMessage(defaultValue, args...),
168 statusCode: UnknownEntity,
169 },
170 }
171}
172
173// UnknownInstanceError means that the managed entity instance (bytes 7..8)
174// does not exist in the ONU.
175type UnknownInstanceError struct {
176 OmciError
177}
178
179// NewUnknownInstanceError creates an UnknownInstanceError
180func NewUnknownInstanceError(args ...interface{}) OmciErrors {
181 defaultValue := "unknown managed entity instance"
182 return &UnknownInstanceError{
183 OmciError: OmciError{
184 err: genMessage(defaultValue, args...),
185 statusCode: UnknownInstance,
186 },
187 }
188}
189
190// DeviceBusyError means that the command could not be processed due
191// to process-related congestion at the ONU. This result code may
192// also be used as a pause indication to the OLT while the ONU
193// conducts a time-consuming operation such as storage of a
194// software image into non-volatile memory.
195type DeviceBusyError struct {
196 OmciError
197}
198
199// NewDeviceBusyError creates a DeviceBusyError
200func NewDeviceBusyError(args ...interface{}) OmciErrors {
201 defaultValue := "device busy"
202 return &DeviceBusyError{
203 OmciError: OmciError{
204 err: genMessage(defaultValue, args...),
205 statusCode: DeviceBusy,
206 },
207 }
208}
209
210// InstanceExistsError means that the ONU already has a managed entity instance
211// that corresponds to the one the OLT is attempting to create.
212type InstanceExistsError struct {
213 OmciError
214}
215
216// NewInstanceExistsError
217func NewInstanceExistsError(args ...interface{}) OmciErrors {
218 defaultValue := "instance exists"
219 return &InstanceExistsError{
220 OmciError: OmciError{
221 err: genMessage(defaultValue, args...),
222 statusCode: InstanceExists,
223 },
224 }
225}
226
227// AttributeFailureError is used to encode failed attributes for Get/Set Requests
228//
229// For Get requests, the failed mask is used to report attributes that could not be
230// retrieved (most likely no space available to serialize) and could not be returned
231// to the caller. The unsupported mask reports attributes the ONU does not support.
232//
233// For Set requests, the failed mask is used to report attributes that have errors
234// (possibly constraints) and could not be set/saved. The unsupported mask reports
235// attributes the ONU does not support.
236//
237// For Create requests that have parameter errors (code 0011), use the NewParameterError()
238// function to signal which attributes were in error
239type AttributeFailureError struct {
240 OmciError
241}
242
243// NewAttributeFailureError is used to ceeate an AttributeFailure error status for
244// Get/Set requests
245func NewAttributeFailureError(failedMask uint16, unsupportedMask uint16, args ...interface{}) OmciErrors {
246 defaultValue := "attribute(s) failed or unknown"
247
248 err := &AttributeFailureError{
249 OmciError: OmciError{
250 err: genMessage(defaultValue, args...),
251 statusCode: AttributeFailure,
252 failureMask: failedMask,
253 unsupportedMask: unsupportedMask,
254 },
255 }
256 return err
257}
258
259// MessageTruncatedError means that the requested attributes could not
260// be added to the frame due to size limitations. This is typically an OMCI Error
261// returned internally by support functions in the OMCI library and used by the
262// frame encoding routines to eventually return an AttributeFailureError
263// result (code 1001)
264type MessageTruncatedError struct {
265 OmciError
266}
267
268// NewMessageTruncatedError creates a MessageTruncatedError message
269func NewMessageTruncatedError(args ...interface{}) OmciErrors {
270 defaultValue := "out-of-space. Cannot fit attribute into message"
271 return &MessageTruncatedError{
272 OmciError: OmciError{
273 err: genMessage(defaultValue, args...),
274 statusCode: ProcessingError,
275 },
276 }
277}
278
279func genMessage(defaultValue string, args ...interface{}) string {
280 switch len(args) {
281 case 0:
282 return defaultValue
283
284 case 1:
285 switch first := args[0].(type) {
286 case string:
287 // Assume a simple, pre-formatted string
288 return args[0].(string)
289
290 case func() string:
291 // Assume a closure with no other arguments used
292 return first()
293
294 default:
295 panic("Unsupported parameter type")
296 }
297 }
298 return fmt.Sprintf(args[0].(string), args[1:]...)
299}