blob: 5e845ff2897a220cf3fa0f8e8301d3b7d9f359ff [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
Chip Boling157c9b92021-04-21 09:58:36 -0500108 ExtendedOffset MsgType = 0x80
Chip Boling6e27b352020-02-14 09:10:01 -0600109)
110
111func (mt MsgType) String() string {
112 switch mt {
113 default:
114 return "Unknown"
115 case Create:
116 return "Create"
117 case Delete:
118 return "Delete"
119 case Set:
120 return "Set"
121 case Get:
122 return "Get"
123 case GetAllAlarms:
124 return "Get All Alarms"
125 case GetAllAlarmsNext:
126 return "Get All Alarms Next"
127 case MibUpload:
128 return "MIB Upload"
129 case MibUploadNext:
130 return "MIB Upload Next"
131 case MibReset:
132 return "MIB Reset"
133 case AlarmNotification:
134 return "Alarm Notification"
135 case AttributeValueChange:
136 return "Attribute Value Change"
137 case Test:
138 return "Test"
139 case StartSoftwareDownload:
140 return "Start Software Download"
141 case DownloadSection:
142 return "Download Section"
143 case EndSoftwareDownload:
144 return "EndSoftware Download"
145 case ActivateSoftware:
146 return "Activate Software"
147 case CommitSoftware:
148 return "Commit Software"
149 case SynchronizeTime:
150 return "Synchronize Time"
151 case Reboot:
152 return "Reboot"
153 case GetNext:
154 return "Get Next"
155 case TestResult:
156 return "Test Result"
157 case GetCurrentData:
158 return "Get Current Data"
159 case SetTable:
160 return "Set Table"
161 }
162}
163
164var allNotificationTypes = [...]MsgType{
165 AlarmNotification,
166 AttributeValueChange,
167 TestResult,
168}
169
170// SupportsMsgType returns true if the managed entity supports the desired
171// Message Type / action
172func SupportsMsgType(entity IManagedEntityDefinition, msgType MsgType) bool {
173 return entity.GetMessageTypes().Contains(msgType)
174}
175
176func IsAutonomousNotification(mt MsgType) bool {
177 for _, m := range allNotificationTypes {
178 if mt == m {
179 return true
180 }
181 }
182 return false
183}
184
185const (
186 // Response status codes
187 Success Results = 0 // command processed successfully
188 ProcessingError Results = 1 // command processing error
189 NotSupported Results = 2 // command not supported
190 ParameterError Results = 3 // parameter error
191 UnknownEntity Results = 4 // unknown managed entity
192 UnknownInstance Results = 5 // unknown managed entity instance
193 DeviceBusy Results = 6 // device busy
194 InstanceExists Results = 7 // instance exists
195 AttributeFailure Results = 9 // Attribute(s) failed or unknown
196)
197
198func (rc Results) String() string {
199 switch rc {
200 default:
201 return "Unknown"
202 case Success:
203 return "Success"
204 case ProcessingError:
205 return "Processing Error"
206 case NotSupported:
207 return "Not Supported"
208 case ParameterError:
209 return "Parameter Error"
210 case UnknownEntity:
211 return "Unknown Entity"
212 case UnknownInstance:
213 return "Unknown Instance"
214 case DeviceBusy:
215 return "Device Busy"
216 case InstanceExists:
217 return "Instance Exists"
218 case AttributeFailure:
219 return "Attribute Failure"
220 }
221}
222
223const (
224 // Access allowed on a Managed Entity attribute
225 Read AttributeAccess = 1 << iota
226 Write
227 SetByCreate
228)
229
230func (access AttributeAccess) String() string {
231 switch access {
232 default:
233 return "Unknown"
234 case Read:
235 return "Read"
236 case Write:
237 return "Write"
238 case SetByCreate:
239 return "SetByCreate"
240 case Read | Write:
241 return "Read/Write"
242 case Read | SetByCreate:
243 return "Read/SetByCreate"
244 case Write | SetByCreate:
245 return "Write/SetByCreate"
246 case Read | Write | SetByCreate:
247 return "Read/Write/SetByCreate"
248 }
249}
250
251// SupportsAttributeAccess returns true if the managed entity attribute
252// supports the desired access
253func SupportsAttributeAccess(attr AttributeDefinition, acc AttributeAccess) bool {
254 return attr.GetAccess().Contains(acc)
255}
256
257type IManagedEntityDefinition interface {
258 GetName() string
259 GetClassID() ClassID
260 GetMessageTypes() mapset.Set
261 GetAllowedAttributeMask() uint16
262 GetAttributeDefinitions() AttributeDefinitionMap
Chip Boling34ebcb62021-02-02 12:13:58 -0600263 GetAlarmMap() AlarmMap
Chip Boling6e27b352020-02-14 09:10:01 -0600264
265 DecodeAttributes(uint16, []byte, gopacket.PacketBuilder, byte) (AttributeValueMap, error)
266 SerializeAttributes(AttributeValueMap, uint16, gopacket.SerializeBuffer, byte, int, bool) (error, uint16)
267}
268
269type IManagedEntity interface {
270 IManagedEntityDefinition
271 GetManagedEntityDefinition() IManagedEntityDefinition
272
273 GetEntityID() uint16
274 SetEntityID(uint16) error
275
276 GetAttributeMask() uint16
277
278 GetAttributeValueMap() AttributeValueMap
279 GetAttribute(string) (interface{}, error)
280 GetAttributeByIndex(uint) (interface{}, error)
281
282 SetAttribute(string, interface{}) error
283 SetAttributeByIndex(uint, interface{}) error
284
285 DeleteAttribute(string) error
286 DeleteAttributeByIndex(uint) error
287}