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