blob: 8924e7db499a3510f233340e885c190025e329a4 [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 */
Chip Boling34ebcb62021-02-02 12:13:58 -060017/*
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 "fmt"
28 "github.com/deckarep/golang-set"
29 "github.com/google/gopacket"
30)
31
32// MsgType represents a OMCI message-type
33type MsgType byte
34
35// MsgType represents the status field in a OMCI Response frame
36type Results byte
37
38// AttributeAccess represents the access allowed to an Attribute. Some MEs
39// are instantiated by the ONU autonomously. Others are instantiated on
40// explicit request of the OLT via a create command, and a few ME types may
41// be instantiated in either way, depending on the ONU architecture or
42// circumstances.
43//
44// Attributes of an ME that is auto-instantiated by the ONU can be read (R),
45// write (W), or read, write (R, W). On the other hand, attributes of a ME
46// that is instantiated by the OLT can be either (R), (W), (R, W),
47// (R, set by create) or (R, W, set by create).
48type AttributeAccess byte
49
50// ClassID is a 16-bit value that uniquely defines a Managed Entity clas
51// from the ITU-T G.988 specification.
52type ClassID uint16
53
Chip Boling34ebcb62021-02-02 12:13:58 -060054// AlarmMap is a mapping of alarm bit numbers to alarm names and can be
55// used during decode of Alarm Notification messages
56type AlarmMap map[uint8]string
57
Chip Boling6e27b352020-02-14 09:10:01 -060058func (cid ClassID) String() string {
59 if entity, err := LoadManagedEntityDefinition(cid); err.StatusCode() == Success {
60 return fmt.Sprintf("[%s] (%d/%#x)",
61 entity.GetManagedEntityDefinition().GetName(), uint16(cid), uint16(cid))
62 }
63 return fmt.Sprintf("unknown ClassID: %d (%#x)", uint16(cid), uint16(cid))
64}
65
66const (
67 // AK (Bit 6), indicates whether this message is an AK to an action request.
68 // If a message is an AK, this bit is set to 1. If the message is not a
69 // response to a command, this bit is set to 0. In messages sent by the OLT,
70 // this bit is always 0.
71 AK byte = 0x20
72
73 // AR (Bit 7), acknowledge request, indicates whether the message requires an
74 // AK. An AK is a response to an action request, not a link layer handshake.
75 // If an AK is expected, this bit is set to 1. If no AK is expected, this bit
76 // is 0. In messages sent by the ONU, this bit is always 0
77 AR byte = 0x40
78
79 // MsgTypeMask provides a mask to get the base message type
80 MsgTypeMask = 0x1F
81)
82
83const (
84 // Message Types
85 Create MsgType = 4
86 Delete MsgType = 6
87 Set MsgType = 8
88 Get MsgType = 9
89 GetAllAlarms MsgType = 11
90 GetAllAlarmsNext MsgType = 12
91 MibUpload MsgType = 13
92 MibUploadNext MsgType = 14
93 MibReset MsgType = 15
94 AlarmNotification MsgType = 16
95 AttributeValueChange MsgType = 17
96 Test MsgType = 18
97 StartSoftwareDownload MsgType = 19
98 DownloadSection MsgType = 20
99 EndSoftwareDownload MsgType = 21
100 ActivateSoftware MsgType = 22
101 CommitSoftware MsgType = 23
102 SynchronizeTime MsgType = 24
103 Reboot MsgType = 25
104 GetNext MsgType = 26
105 TestResult MsgType = 27
106 GetCurrentData MsgType = 28
107 SetTable MsgType = 29 // Defined in Extended Message Set Only
108)
109
110func (mt MsgType) String() string {
111 switch mt {
112 default:
113 return "Unknown"
114 case Create:
115 return "Create"
116 case Delete:
117 return "Delete"
118 case Set:
119 return "Set"
120 case Get:
121 return "Get"
122 case GetAllAlarms:
123 return "Get All Alarms"
124 case GetAllAlarmsNext:
125 return "Get All Alarms Next"
126 case MibUpload:
127 return "MIB Upload"
128 case MibUploadNext:
129 return "MIB Upload Next"
130 case MibReset:
131 return "MIB Reset"
132 case AlarmNotification:
133 return "Alarm Notification"
134 case AttributeValueChange:
135 return "Attribute Value Change"
136 case Test:
137 return "Test"
138 case StartSoftwareDownload:
139 return "Start Software Download"
140 case DownloadSection:
141 return "Download Section"
142 case EndSoftwareDownload:
143 return "EndSoftware Download"
144 case ActivateSoftware:
145 return "Activate Software"
146 case CommitSoftware:
147 return "Commit Software"
148 case SynchronizeTime:
149 return "Synchronize Time"
150 case Reboot:
151 return "Reboot"
152 case GetNext:
153 return "Get Next"
154 case TestResult:
155 return "Test Result"
156 case GetCurrentData:
157 return "Get Current Data"
158 case SetTable:
159 return "Set Table"
160 }
161}
162
163var allNotificationTypes = [...]MsgType{
164 AlarmNotification,
165 AttributeValueChange,
166 TestResult,
167}
168
169// SupportsMsgType returns true if the managed entity supports the desired
170// Message Type / action
171func SupportsMsgType(entity IManagedEntityDefinition, msgType MsgType) bool {
172 return entity.GetMessageTypes().Contains(msgType)
173}
174
175func IsAutonomousNotification(mt MsgType) bool {
176 for _, m := range allNotificationTypes {
177 if mt == m {
178 return true
179 }
180 }
181 return false
182}
183
184const (
185 // Response status codes
186 Success Results = 0 // command processed successfully
187 ProcessingError Results = 1 // command processing error
188 NotSupported Results = 2 // command not supported
189 ParameterError Results = 3 // parameter error
190 UnknownEntity Results = 4 // unknown managed entity
191 UnknownInstance Results = 5 // unknown managed entity instance
192 DeviceBusy Results = 6 // device busy
193 InstanceExists Results = 7 // instance exists
194 AttributeFailure Results = 9 // Attribute(s) failed or unknown
195)
196
197func (rc Results) String() string {
198 switch rc {
199 default:
200 return "Unknown"
201 case Success:
202 return "Success"
203 case ProcessingError:
204 return "Processing Error"
205 case NotSupported:
206 return "Not Supported"
207 case ParameterError:
208 return "Parameter Error"
209 case UnknownEntity:
210 return "Unknown Entity"
211 case UnknownInstance:
212 return "Unknown Instance"
213 case DeviceBusy:
214 return "Device Busy"
215 case InstanceExists:
216 return "Instance Exists"
217 case AttributeFailure:
218 return "Attribute Failure"
219 }
220}
221
222const (
223 // Access allowed on a Managed Entity attribute
224 Read AttributeAccess = 1 << iota
225 Write
226 SetByCreate
227)
228
229func (access AttributeAccess) String() string {
230 switch access {
231 default:
232 return "Unknown"
233 case Read:
234 return "Read"
235 case Write:
236 return "Write"
237 case SetByCreate:
238 return "SetByCreate"
239 case Read | Write:
240 return "Read/Write"
241 case Read | SetByCreate:
242 return "Read/SetByCreate"
243 case Write | SetByCreate:
244 return "Write/SetByCreate"
245 case Read | Write | SetByCreate:
246 return "Read/Write/SetByCreate"
247 }
248}
249
250// SupportsAttributeAccess returns true if the managed entity attribute
251// supports the desired access
252func SupportsAttributeAccess(attr AttributeDefinition, acc AttributeAccess) bool {
253 return attr.GetAccess().Contains(acc)
254}
255
256type IManagedEntityDefinition interface {
257 GetName() string
258 GetClassID() ClassID
259 GetMessageTypes() mapset.Set
260 GetAllowedAttributeMask() uint16
261 GetAttributeDefinitions() AttributeDefinitionMap
Chip Boling34ebcb62021-02-02 12:13:58 -0600262 GetAlarmMap() AlarmMap
Chip Boling6e27b352020-02-14 09:10:01 -0600263
264 DecodeAttributes(uint16, []byte, gopacket.PacketBuilder, byte) (AttributeValueMap, error)
265 SerializeAttributes(AttributeValueMap, uint16, gopacket.SerializeBuffer, byte, int, bool) (error, uint16)
266}
267
268type IManagedEntity interface {
269 IManagedEntityDefinition
270 GetManagedEntityDefinition() IManagedEntityDefinition
271
272 GetEntityID() uint16
273 SetEntityID(uint16) error
274
275 GetAttributeMask() uint16
276
277 GetAttributeValueMap() AttributeValueMap
278 GetAttribute(string) (interface{}, error)
279 GetAttributeByIndex(uint) (interface{}, error)
280
281 SetAttribute(string, interface{}) error
282 SetAttributeByIndex(uint, interface{}) error
283
284 DeleteAttribute(string) error
285 DeleteAttributeByIndex(uint) error
286}