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