blob: 6776b06506ebda027197bde037df84838ce4243b [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
Matteo Scandolof9d43412021-01-12 11:11:34 -08003 * Copyright 2020-present Open Networking Foundation
4
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07005 * 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
Matteo Scandolof9d43412021-01-12 11:11:34 -08008
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07009 * http://www.apache.org/licenses/LICENSE-2.0
Matteo Scandolof9d43412021-01-12 11:11:34 -080010
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070011 * 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.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070016 */
Matteo Scandolof9d43412021-01-12 11:11:34 -080017
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070018package omci
19
20import (
21 "encoding/binary"
22 "errors"
23 "fmt"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070024 "github.com/google/gopacket"
Matteo Scandolof9d43412021-01-12 11:11:34 -080025 me "github.com/opencord/omci-lib-go/generated"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070026)
27
28// MessageType is the OMCI Message Type or'ed with the AR/AK flags as appropriate.
29type MessageType byte
30
31const (
Girish Gowdrae2683102021-03-05 08:24:26 -080032 CreateRequestType = MessageType(byte(me.Create) | me.AR)
33 CreateResponseType = MessageType(byte(me.Create) | me.AK)
34 DeleteRequestType = MessageType(byte(me.Delete) | me.AR)
35 DeleteResponseType = MessageType(byte(me.Delete) | me.AK)
36 SetRequestType = MessageType(byte(me.Set) | me.AR)
37 SetResponseType = MessageType(byte(me.Set) | me.AK)
38 GetRequestType = MessageType(byte(me.Get) | me.AR)
39 GetResponseType = MessageType(byte(me.Get) | me.AK)
40 GetAllAlarmsRequestType = MessageType(byte(me.GetAllAlarms) | me.AR)
41 GetAllAlarmsResponseType = MessageType(byte(me.GetAllAlarms) | me.AK)
42 GetAllAlarmsNextRequestType = MessageType(byte(me.GetAllAlarmsNext) | me.AR)
43 GetAllAlarmsNextResponseType = MessageType(byte(me.GetAllAlarmsNext) | me.AK)
44 MibUploadRequestType = MessageType(byte(me.MibUpload) | me.AR)
45 MibUploadResponseType = MessageType(byte(me.MibUpload) | me.AK)
46 MibUploadNextRequestType = MessageType(byte(me.MibUploadNext) | me.AR)
47 MibUploadNextResponseType = MessageType(byte(me.MibUploadNext) | me.AK)
48 MibResetRequestType = MessageType(byte(me.MibReset) | me.AR)
49 MibResetResponseType = MessageType(byte(me.MibReset) | me.AK)
50 TestRequestType = MessageType(byte(me.Test) | me.AR)
51 TestResponseType = MessageType(byte(me.Test) | me.AK)
52 StartSoftwareDownloadRequestType = MessageType(byte(me.StartSoftwareDownload) | me.AR)
53 StartSoftwareDownloadResponseType = MessageType(byte(me.StartSoftwareDownload) | me.AK)
54 DownloadSectionRequestType = MessageType(me.DownloadSection) // me.AR is optional
55 DownloadSectionRequestWithResponseType = MessageType(byte(me.DownloadSection) | me.AR)
56 DownloadSectionResponseType = MessageType(byte(me.DownloadSection) | me.AK)
57 EndSoftwareDownloadRequestType = MessageType(byte(me.EndSoftwareDownload) | me.AR)
58 EndSoftwareDownloadResponseType = MessageType(byte(me.EndSoftwareDownload) | me.AK)
59 ActivateSoftwareRequestType = MessageType(byte(me.ActivateSoftware) | me.AR)
60 ActivateSoftwareResponseType = MessageType(byte(me.ActivateSoftware) | me.AK)
61 CommitSoftwareRequestType = MessageType(byte(me.CommitSoftware) | me.AR)
62 CommitSoftwareResponseType = MessageType(byte(me.CommitSoftware) | me.AK)
63 SynchronizeTimeRequestType = MessageType(byte(me.SynchronizeTime) | me.AR)
64 SynchronizeTimeResponseType = MessageType(byte(me.SynchronizeTime) | me.AK)
65 RebootRequestType = MessageType(byte(me.Reboot) | me.AR)
66 RebootResponseType = MessageType(byte(me.Reboot) | me.AK)
67 GetNextRequestType = MessageType(byte(me.GetNext) | me.AR)
68 GetNextResponseType = MessageType(byte(me.GetNext) | me.AK)
69 GetCurrentDataRequestType = MessageType(byte(me.GetCurrentData) | me.AR)
70 GetCurrentDataResponseType = MessageType(byte(me.GetCurrentData) | me.AK)
71 SetTableRequestType = MessageType(byte(me.SetTable) | me.AR)
72 SetTableResponseType = MessageType(byte(me.SetTable) | me.AK)
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070073 // Autonomous ONU messages
74 AlarmNotificationType = MessageType(byte(me.AlarmNotification))
75 AttributeValueChangeType = MessageType(byte(me.AttributeValueChange))
76 TestResultType = MessageType(byte(me.TestResult))
77)
78
79func (mt MessageType) String() string {
80 switch mt {
81 default:
82 return "Unknown"
83
84 case CreateRequestType:
85 return "Create Request"
86 case CreateResponseType:
87 return "Create Response"
88 case DeleteRequestType:
89 return "Delete Request"
90 case DeleteResponseType:
91 return "Delete Response"
92 case SetRequestType:
93 return "Set Request"
94 case SetResponseType:
95 return "Set Response"
96 case GetRequestType:
97 return "Get Request"
98 case GetResponseType:
99 return "Get Response"
100 case GetAllAlarmsRequestType:
101 return "Get All Alarms Request"
102 case GetAllAlarmsResponseType:
103 return "Get All Alarms Response"
104 case GetAllAlarmsNextRequestType:
105 return "Get All Alarms Next Request"
106 case GetAllAlarmsNextResponseType:
107 return "Get All Alarms Next Response"
108 case MibUploadRequestType:
109 return "MIB Upload Request"
110 case MibUploadResponseType:
111 return "MIB Upload Response"
112 case MibUploadNextRequestType:
113 return "MIB Upload Next Request"
114 case MibUploadNextResponseType:
115 return "MIB Upload Next Response"
116 case MibResetRequestType:
117 return "MIB Reset Request"
118 case MibResetResponseType:
119 return "MIB Reset Response"
120 case TestRequestType:
121 return "Test Request"
122 case TestResponseType:
123 return "Test Response"
124 case StartSoftwareDownloadRequestType:
125 return "Start Software Download Request"
126 case StartSoftwareDownloadResponseType:
127 return "Start Software Download Response"
128 case DownloadSectionRequestType:
129 return "Download Section Request"
130 case DownloadSectionResponseType:
131 return "Download Section Response"
132 case EndSoftwareDownloadRequestType:
133 return "End Software Download Request"
134 case EndSoftwareDownloadResponseType:
135 return "End Software Download Response"
136 case ActivateSoftwareRequestType:
137 return "Activate Software Request"
138 case ActivateSoftwareResponseType:
139 return "Activate Software Response"
140 case CommitSoftwareRequestType:
141 return "Commit Software Request"
142 case CommitSoftwareResponseType:
143 return "Commit Software Response"
144 case SynchronizeTimeRequestType:
145 return "Synchronize Time Request"
146 case SynchronizeTimeResponseType:
147 return "Synchronize Time Response"
148 case RebootRequestType:
149 return "Reboot Request"
150 case RebootResponseType:
151 return "Reboot Response"
152 case GetNextRequestType:
153 return "Get Next Request"
154 case GetNextResponseType:
155 return "Get Next Response"
156 case GetCurrentDataRequestType:
157 return "Get Current Data Request"
158 case GetCurrentDataResponseType:
159 return "Get Current Data Response"
160 case SetTableRequestType:
161 return "Set Table Request"
162 case SetTableResponseType:
163 return "Set Table Response"
164 case AlarmNotificationType:
165 return "Alarm Notification"
166 case AttributeValueChangeType:
167 return "Attribute Value Change"
168 case TestResultType:
169 return "Test Result"
170 }
171}
172
173/////////////////////////////////////////////////////////////////////////////
174// CreateRequest
175type CreateRequest struct {
176 MeBasePacket
177 Attributes me.AttributeValueMap
178}
179
180func (omci *CreateRequest) String() string {
181 return fmt.Sprintf("%v, attributes: %v", omci.MeBasePacket.String(), omci.Attributes)
182}
183
Matteo Scandolof9d43412021-01-12 11:11:34 -0800184// DecodeFromBytes decodes the given bytes of a Create Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700185func (omci *CreateRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
186 // Common ClassID/EntityID decode in msgBase
187 err := omci.MeBasePacket.DecodeFromBytes(data, p)
188 if err != nil {
189 return err
190 }
191 // Create attribute mask for all set-by-create entries
Matteo Scandolof9d43412021-01-12 11:11:34 -0800192 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700193 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800194 if omciErr.StatusCode() != me.Success {
195 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700196 }
197 // ME needs to support Create
198 if !me.SupportsMsgType(meDefinition, me.Create) {
199 return me.NewProcessingError("managed entity does not support Create Message-Type")
200 }
201 var sbcMask uint16
Matteo Scandolof9d43412021-01-12 11:11:34 -0800202 for index, attr := range meDefinition.GetAttributeDefinitions() {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700203 if me.SupportsAttributeAccess(attr, me.SetByCreate) {
204 if index == 0 {
205 continue // Skip Entity ID
206 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800207 sbcMask |= attr.Mask
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700208 }
209 }
210 // Attribute decode
211 omci.Attributes, err = meDefinition.DecodeAttributes(sbcMask, data[4:], p, byte(CreateRequestType))
212 if err != nil {
213 return err
214 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800215 if eidDef, eidDefOK := meDefinition.GetAttributeDefinitions()[0]; eidDefOK {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700216 omci.Attributes[eidDef.GetName()] = omci.EntityInstance
217 return nil
218 }
219 panic("All Managed Entities have an EntityID attribute")
220}
221
222func decodeCreateRequest(data []byte, p gopacket.PacketBuilder) error {
223 omci := &CreateRequest{}
224 omci.MsgLayerType = LayerTypeCreateRequest
225 return decodingLayerDecoder(omci, data, p)
226}
227
Matteo Scandolof9d43412021-01-12 11:11:34 -0800228// SerializeTo provides serialization of an Create Request Message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700229func (omci *CreateRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
230 // Basic (common) OMCI Header is 8 octets, 10
231 err := omci.MeBasePacket.SerializeTo(b)
232 if err != nil {
233 return err
234 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800235 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700236 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800237 if omciErr.StatusCode() != me.Success {
238 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700239 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800240 // Create attribute mask of SetByCreate attributes that should be present in the provided
241 // attributes.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700242 var sbcMask uint16
Matteo Scandolof9d43412021-01-12 11:11:34 -0800243 for index, attr := range meDefinition.GetAttributeDefinitions() {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700244 if me.SupportsAttributeAccess(attr, me.SetByCreate) {
245 if index == 0 {
246 continue // Skip Entity ID
247 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800248 sbcMask |= attr.Mask
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700249 }
250 }
251 // Attribute serialization
252 // TODO: Only Baseline supported at this time
253 bytesAvailable := MaxBaselineLength - 8 - 8
Matteo Scandolof9d43412021-01-12 11:11:34 -0800254 err, _ = meDefinition.SerializeAttributes(omci.Attributes, sbcMask, b, byte(CreateRequestType), bytesAvailable, false)
255 return err
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700256}
257
258/////////////////////////////////////////////////////////////////////////////
259// CreateResponse
260type CreateResponse struct {
261 MeBasePacket
262 Result me.Results
263 AttributeExecutionMask uint16 // Used when Result == ParameterError
264}
265
266func (omci *CreateResponse) String() string {
267 return fmt.Sprintf("%v, Result: %d (%v), Mask: %#x",
268 omci.MeBasePacket.String(), omci.Result, omci.Result, omci.AttributeExecutionMask)
269}
270
Matteo Scandolof9d43412021-01-12 11:11:34 -0800271// DecodeFromBytes decodes the given bytes of a Create Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700272func (omci *CreateResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
273 // Common ClassID/EntityID decode in msgBase
274 err := omci.MeBasePacket.DecodeFromBytes(data, p)
275 if err != nil {
276 return err
277 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800278 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700279 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800280 if omciErr.StatusCode() != me.Success {
281 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700282 }
283 // ME needs to support Create
284 if !me.SupportsMsgType(entity, me.Create) {
285 return me.NewProcessingError("managed entity does not support the Create Message-Type")
286 }
287 omci.Result = me.Results(data[4])
288 if omci.Result == me.ParameterError {
289 omci.AttributeExecutionMask = binary.BigEndian.Uint16(data[5:])
290 // TODO: validation that attributes set in mask are SetByCreate would be good here
291 }
292 return nil
293}
294
295func decodeCreateResponse(data []byte, p gopacket.PacketBuilder) error {
296 omci := &CreateResponse{}
297 omci.MsgLayerType = LayerTypeCreateResponse
298 return decodingLayerDecoder(omci, data, p)
299}
300
Matteo Scandolof9d43412021-01-12 11:11:34 -0800301// SerializeTo provides serialization of an Create Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700302func (omci *CreateResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
303 // Basic (common) OMCI Header is 8 octets, 10
304 err := omci.MeBasePacket.SerializeTo(b)
305 if err != nil {
306 return err
307 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800308 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700309 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800310 if omciErr.StatusCode() != me.Success {
311 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700312 }
313 // ME needs to support Create
314 if !me.SupportsMsgType(entity, me.Create) {
315 return me.NewProcessingError("managed entity does not support the Create Message-Type")
316 }
317 bytes, err := b.AppendBytes(3)
318 if err != nil {
319 return err
320 }
321 bytes[0] = byte(omci.Result)
322 if omci.Result == me.ParameterError {
323 // TODO: validation that attributes set in mask are SetByCreate would be good here
324 binary.BigEndian.PutUint16(bytes[1:], omci.AttributeExecutionMask)
325 } else {
326 binary.BigEndian.PutUint16(bytes[1:], 0)
327 }
328 return nil
329}
330
331/////////////////////////////////////////////////////////////////////////////
332// DeleteRequest
333type DeleteRequest struct {
334 MeBasePacket
335}
336
337func (omci *DeleteRequest) String() string {
338 return fmt.Sprintf("%v", omci.MeBasePacket.String())
339}
340
Matteo Scandolof9d43412021-01-12 11:11:34 -0800341// DecodeFromBytes decodes the given bytes of a Delete Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700342func (omci *DeleteRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
343 // Common ClassID/EntityID decode in msgBase
344 err := omci.MeBasePacket.DecodeFromBytes(data, p)
345 if err != nil {
346 return err
347 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800348 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700349 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800350 if omciErr.StatusCode() != me.Success {
351 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700352 }
353 // ME needs to support Delete
354 if !me.SupportsMsgType(entity, me.Delete) {
355 return me.NewProcessingError("managed entity does not support the Delete Message-Type")
356 }
357 return nil
358}
359
360func decodeDeleteRequest(data []byte, p gopacket.PacketBuilder) error {
361 omci := &DeleteRequest{}
362 omci.MsgLayerType = LayerTypeDeleteRequest
363 return decodingLayerDecoder(omci, data, p)
364}
365
Matteo Scandolof9d43412021-01-12 11:11:34 -0800366// SerializeTo provides serialization of an Delete Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700367func (omci *DeleteRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
368 // Basic (common) OMCI Header is 8 octets, 10
369 err := omci.MeBasePacket.SerializeTo(b)
370 if err != nil {
371 return err
372 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800373 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700374 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800375 if omciErr.StatusCode() != me.Success {
376 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700377 }
378 // ME needs to support Delete
379 if !me.SupportsMsgType(entity, me.Delete) {
380 return me.NewProcessingError("managed entity does not support the Delete Message-Type")
381 }
382 return nil
383}
384
385/////////////////////////////////////////////////////////////////////////////
386// DeleteResponse
387type DeleteResponse struct {
388 MeBasePacket
389 Result me.Results
390}
391
392func (omci *DeleteResponse) String() string {
393 return fmt.Sprintf("%v, Result: %d (%v)",
394 omci.MeBasePacket.String(), omci.Result, omci.Result)
395}
396
Matteo Scandolof9d43412021-01-12 11:11:34 -0800397// DecodeFromBytes decodes the given bytes of a Delete Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700398func (omci *DeleteResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
399 // Common ClassID/EntityID decode in msgBase
400 err := omci.MeBasePacket.DecodeFromBytes(data, p)
401 if err != nil {
402 return err
403 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800404 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700405 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800406 if omciErr.StatusCode() != me.Success {
407 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700408 }
409 // ME needs to support Delete
410 if !me.SupportsMsgType(entity, me.Delete) {
411 return me.NewProcessingError("managed entity does not support the Delete Message-Type")
412 }
413 omci.Result = me.Results(data[4])
414 return nil
415}
416
417func decodeDeleteResponse(data []byte, p gopacket.PacketBuilder) error {
418 omci := &DeleteResponse{}
419 omci.MsgLayerType = LayerTypeDeleteResponse
420 return decodingLayerDecoder(omci, data, p)
421}
422
Matteo Scandolof9d43412021-01-12 11:11:34 -0800423// SerializeTo provides serialization of an Delete Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700424func (omci *DeleteResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
425 // Basic (common) OMCI Header is 8 octets, 10
426 err := omci.MeBasePacket.SerializeTo(b)
427 if err != nil {
428 return err
429 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800430 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700431 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800432 if omciErr.StatusCode() != me.Success {
433 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700434 }
435 // ME needs to support Delete
436 if !me.SupportsMsgType(entity, me.Delete) {
437 return me.NewProcessingError("managed entity does not support the Delete Message-Type")
438 }
439 bytes, err := b.AppendBytes(1)
440 if err != nil {
441 return err
442 }
443 bytes[0] = byte(omci.Result)
444 return nil
445}
446
447/////////////////////////////////////////////////////////////////////////////
448// SetRequest
449type SetRequest struct {
450 MeBasePacket
451 AttributeMask uint16
452 Attributes me.AttributeValueMap
453}
454
455func (omci *SetRequest) String() string {
456 return fmt.Sprintf("%v, Mask: %#x, attributes: %v",
457 omci.MeBasePacket.String(), omci.AttributeMask, omci.Attributes)
458}
459
Matteo Scandolof9d43412021-01-12 11:11:34 -0800460// DecodeFromBytes decodes the given bytes of a Set Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700461func (omci *SetRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
462 // Common ClassID/EntityID decode in msgBase
463 err := omci.MeBasePacket.DecodeFromBytes(data, p)
464 if err != nil {
465 return err
466 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800467 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700468 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800469 if omciErr.StatusCode() != me.Success {
470 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700471 }
472 // ME needs to support Set
473 if !me.SupportsMsgType(meDefinition, me.Set) {
474 return me.NewProcessingError("managed entity does not support Set Message-Type")
475 }
476 omci.AttributeMask = binary.BigEndian.Uint16(data[4:6])
477
478 // Attribute decode
479 omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[6:], p, byte(SetRequestType))
480 if err != nil {
481 return err
482 }
483 // Validate all attributes support write
484 for attrName := range omci.Attributes {
485 attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
486 if err != nil {
487 return err
488 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800489 if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Write) {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700490 msg := fmt.Sprintf("attribute '%v' does not support write access", attrName)
491 return me.NewProcessingError(msg)
492 }
493 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800494 if eidDef, eidDefOK := meDefinition.GetAttributeDefinitions()[0]; eidDefOK {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700495 omci.Attributes[eidDef.GetName()] = omci.EntityInstance
496 return nil
497 }
498 panic("All Managed Entities have an EntityID attribute")
499}
500
501func decodeSetRequest(data []byte, p gopacket.PacketBuilder) error {
502 omci := &SetRequest{}
503 omci.MsgLayerType = LayerTypeSetRequest
504 return decodingLayerDecoder(omci, data, p)
505}
506
Matteo Scandolof9d43412021-01-12 11:11:34 -0800507// SerializeTo provides serialization of an Set Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700508func (omci *SetRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
509 // Basic (common) OMCI Header is 8 octets, 10
510 err := omci.MeBasePacket.SerializeTo(b)
511 if err != nil {
512 return err
513 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800514 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700515 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800516 if omciErr.StatusCode() != me.Success {
517 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700518 }
519 // ME needs to support Set
520 if !me.SupportsMsgType(meDefinition, me.Set) {
521 return me.NewProcessingError("managed entity does not support Set Message-Type")
522 }
523 // Validate all attributes support write
524 for attrName := range omci.Attributes {
525 attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
526 if err != nil {
527 return err
528 }
529 // Do not test for write of Entity ID in the attribute list
Matteo Scandolof9d43412021-01-12 11:11:34 -0800530 if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Write) {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700531 // TODO: Check ITU spec to see if this should be listed as a failed
532 // attribute and not a processing error.
533 msg := fmt.Sprintf("attribute '%v' does not support write access", attrName)
534 return me.NewProcessingError(msg)
535 }
536 }
537 bytes, err := b.AppendBytes(2)
538 if err != nil {
539 return err
540 }
541 binary.BigEndian.PutUint16(bytes, omci.AttributeMask)
542
543 // Attribute serialization
544 // TODO: Only Baseline supported at this time
545 bytesAvailable := MaxBaselineLength - 10 - 8
546
Matteo Scandolof9d43412021-01-12 11:11:34 -0800547 err, _ = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b,
548 byte(SetRequestType), bytesAvailable, false)
549 return err
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700550}
551
552/////////////////////////////////////////////////////////////////////////////
553// SetResponse
554type SetResponse struct {
555 MeBasePacket
556 Result me.Results
557 UnsupportedAttributeMask uint16
558 FailedAttributeMask uint16
559}
560
561func (omci *SetResponse) String() string {
562 return fmt.Sprintf("%v, Result: %d (%v), Unsupported Mask: %#x, Failed Mask: %#x",
563 omci.MeBasePacket.String(), omci.Result, omci.Result, omci.UnsupportedAttributeMask,
564 omci.FailedAttributeMask)
565}
566
Matteo Scandolof9d43412021-01-12 11:11:34 -0800567// DecodeFromBytes decodes the given bytes of a Set Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700568func (omci *SetResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
569 // Common ClassID/EntityID decode in msgBase
570 err := omci.MeBasePacket.DecodeFromBytes(data, p)
571 if err != nil {
572 return err
573 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800574 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700575 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800576 if omciErr.StatusCode() != me.Success {
577 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700578 }
579 // ME needs to support Set
580 if !me.SupportsMsgType(entity, me.Set) {
581 return me.NewProcessingError("managed entity does not support the Delete Message-Type")
582 }
583 omci.Result = me.Results(data[4])
584
585 if omci.Result == me.AttributeFailure {
586 omci.UnsupportedAttributeMask = binary.BigEndian.Uint16(data[5:7])
587 omci.FailedAttributeMask = binary.BigEndian.Uint16(data[7:9])
588 }
589 return nil
590}
591
592func decodeSetResponse(data []byte, p gopacket.PacketBuilder) error {
593 omci := &SetResponse{}
594 omci.MsgLayerType = LayerTypeSetResponse
595 return decodingLayerDecoder(omci, data, p)
596}
597
Matteo Scandolof9d43412021-01-12 11:11:34 -0800598// SerializeTo provides serialization of an Set Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700599func (omci *SetResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
600 // Basic (common) OMCI Header is 8 octets, 10
601 err := omci.MeBasePacket.SerializeTo(b)
602 if err != nil {
603 return err
604 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800605 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700606 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800607 if omciErr.StatusCode() != me.Success {
608 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700609 }
610 // ME needs to support Set
611 if !me.SupportsMsgType(entity, me.Set) {
612 return me.NewProcessingError("managed entity does not support the Set Message-Type")
613 }
614 bytes, err := b.AppendBytes(5)
615 if err != nil {
616 return err
617 }
618 bytes[0] = byte(omci.Result)
619 binary.BigEndian.PutUint16(bytes[1:3], omci.UnsupportedAttributeMask)
620 binary.BigEndian.PutUint16(bytes[3:5], omci.FailedAttributeMask)
621 return nil
622}
623
624/////////////////////////////////////////////////////////////////////////////
625// GetRequest
626type GetRequest struct {
627 MeBasePacket
628 AttributeMask uint16
629}
630
631func (omci *GetRequest) String() string {
632 return fmt.Sprintf("%v, Mask: %#x",
633 omci.MeBasePacket.String(), omci.AttributeMask)
634}
Matteo Scandolof9d43412021-01-12 11:11:34 -0800635
636// DecodeFromBytes decodes the given bytes of a Get Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700637func (omci *GetRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
638 // Common ClassID/EntityID decode in msgBase
639 err := omci.MeBasePacket.DecodeFromBytes(data, p)
640 if err != nil {
641 return err
642 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800643 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700644 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800645 if omciErr.StatusCode() != me.Success {
646 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700647 }
648 // ME needs to support Get
649 if !me.SupportsMsgType(meDefinition, me.Get) {
650 return me.NewProcessingError("managed entity does not support Get Message-Type")
651 }
652 omci.AttributeMask = binary.BigEndian.Uint16(data[4:6])
653 return nil
654}
655
656func decodeGetRequest(data []byte, p gopacket.PacketBuilder) error {
657 omci := &GetRequest{}
658 omci.MsgLayerType = LayerTypeGetRequest
659 return decodingLayerDecoder(omci, data, p)
660}
661
Matteo Scandolof9d43412021-01-12 11:11:34 -0800662// SerializeTo provides serialization of an Get Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700663func (omci *GetRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
664 // Basic (common) OMCI Header is 8 octets, 10
665 err := omci.MeBasePacket.SerializeTo(b)
666 if err != nil {
667 return err
668 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800669 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700670 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800671 if omciErr.StatusCode() != me.Success {
672 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700673 }
674 // ME needs to support Set
675 if !me.SupportsMsgType(meDefinition, me.Get) {
676 return me.NewProcessingError("managed entity does not support Get Message-Type")
677 }
678 bytes, err := b.AppendBytes(2)
679 if err != nil {
680 return err
681 }
682 binary.BigEndian.PutUint16(bytes, omci.AttributeMask)
683 return nil
684}
685
686/////////////////////////////////////////////////////////////////////////////
687// GetResponse
688type GetResponse struct {
689 MeBasePacket
690 Result me.Results
691 AttributeMask uint16
692 Attributes me.AttributeValueMap
693 UnsupportedAttributeMask uint16
694 FailedAttributeMask uint16
695}
696
697func (omci *GetResponse) String() string {
698 return fmt.Sprintf("%v, Result: %d (%v), Mask: %#x, Unsupported: %#x, Failed: %#x, attributes: %v",
699 omci.MeBasePacket.String(), omci.Result, omci.Result, omci.AttributeMask,
700 omci.UnsupportedAttributeMask, omci.FailedAttributeMask, omci.Attributes)
701}
702
Matteo Scandolof9d43412021-01-12 11:11:34 -0800703// DecodeFromBytes decodes the given bytes of a Get Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700704func (omci *GetResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
705 // Common ClassID/EntityID decode in msgBase
706 err := omci.MeBasePacket.DecodeFromBytes(data, p)
707 if err != nil {
708 return err
709 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800710 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700711 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800712 if omciErr.StatusCode() != me.Success {
713 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700714 }
715 // ME needs to support Get
716 if !me.SupportsMsgType(meDefinition, me.Get) {
717 return me.NewProcessingError("managed entity does not support Get Message-Type")
718 }
719 omci.Result = me.Results(data[4])
720 omci.AttributeMask = binary.BigEndian.Uint16(data[5:7])
721
722 // Attribute decode. Note that the ITU-T G.988 specification states that the
723 // Unsupported and Failed attribute masks are always present
724 // but only valid if the status code== 9. However some XGS
725 // ONUs (T&W and Alpha, perhaps more) will use these last 4
726 // octets for data if the status code == 0. So accommodate
727 // this behaviour in favor of greater interoperability.
728 lastOctet := 36
Matteo Scandolof9d43412021-01-12 11:11:34 -0800729
730 switch omci.Result {
731 case me.ProcessingError, me.NotSupported, me.UnknownEntity, me.UnknownInstance, me.DeviceBusy:
732 return nil // Done (do not try and decode attributes)
733
734 case me.AttributeFailure:
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700735 lastOctet = 32
736 }
737 omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[7:lastOctet], p, byte(GetResponseType))
738 if err != nil {
739 return err
740 }
741 // If Attribute failed or Unknown, decode optional attribute mask
742 if omci.Result == me.AttributeFailure {
743 omci.UnsupportedAttributeMask = binary.BigEndian.Uint16(data[32:34])
744 omci.FailedAttributeMask = binary.BigEndian.Uint16(data[34:36])
745 }
746 // Validate all attributes support read
747 for attrName := range omci.Attributes {
748 attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
749 if err != nil {
750 return err
751 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800752 if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Read) {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700753 msg := fmt.Sprintf("attribute '%v' does not support read access", attrName)
754 return me.NewProcessingError(msg)
755 }
756 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800757 if eidDef, eidDefOK := meDefinition.GetAttributeDefinitions()[0]; eidDefOK {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700758 omci.Attributes[eidDef.GetName()] = omci.EntityInstance
759 return nil
760 }
761 panic("All Managed Entities have an EntityID attribute")
762}
763
764func decodeGetResponse(data []byte, p gopacket.PacketBuilder) error {
765 omci := &GetResponse{}
766 omci.MsgLayerType = LayerTypeGetResponse
767 return decodingLayerDecoder(omci, data, p)
768}
769
Matteo Scandolof9d43412021-01-12 11:11:34 -0800770// SerializeTo provides serialization of an Get Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700771func (omci *GetResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
772 // Basic (common) OMCI Header is 8 octets, 10
Matteo Scandolof9d43412021-01-12 11:11:34 -0800773 if err := omci.MeBasePacket.SerializeTo(b); err != nil {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700774 return err
775 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800776 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700777 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800778
779 if omciErr.StatusCode() != me.Success {
780 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700781 }
782 // ME needs to support Get
783 if !me.SupportsMsgType(meDefinition, me.Get) {
784 return me.NewProcessingError("managed entity does not support the Get Message-Type")
785 }
786 bytes, err := b.AppendBytes(3)
787 if err != nil {
788 return err
789 }
790 bytes[0] = byte(omci.Result)
791 binary.BigEndian.PutUint16(bytes[1:3], omci.AttributeMask)
792
793 // Validate all attributes support read
794 for attrName := range omci.Attributes {
795 attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
796 if err != nil {
797 return err
798 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800799 if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Read) {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700800 msg := fmt.Sprintf("attribute '%v' does not support read access", attrName)
801 return me.NewProcessingError(msg)
802 }
803 }
804 // Attribute serialization
805 switch omci.Result {
806 default:
807 break
808
809 case me.Success, me.AttributeFailure:
810 // TODO: Baseline only supported at this time)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800811 available := MaxBaselineLength - 11 - 4 - 8
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700812
Matteo Scandolof9d43412021-01-12 11:11:34 -0800813 // Serialize to temporary buffer if we may need to reset values due to
814 // recoverable truncation errors
815 origBuffer := b
816 b := gopacket.NewSerializeBuffer()
817
818 err, failedMask := meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b, byte(GetResponseType),
819 available, opts.FixLengths)
820
821 if err == nil && failedMask != 0 && opts.FixLengths {
822 // Not all attributes would fit
823 omci.FailedAttributeMask |= failedMask
824 omci.AttributeMask &= ^failedMask
825 omci.Result = me.AttributeFailure
826
827 // Adjust already recorded values
828 bytes[0] = byte(omci.Result)
829 binary.BigEndian.PutUint16(bytes[1:3], omci.AttributeMask)
830 } else if err != nil {
831 return err
832 }
833 // Copy over attributes to the original serialization buffer
834 newSpace, err := origBuffer.AppendBytes(len(b.Bytes()))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700835 if err != nil {
836 return err
837 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800838 copy(newSpace, b.Bytes())
839 b = origBuffer
840
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700841 // Calculate space left. Max - msgType header - OMCI trailer - spacedUsedSoFar
842 bytesLeft := MaxBaselineLength - 4 - 8 - len(b.Bytes())
843
844 remainingBytes, err := b.AppendBytes(bytesLeft + 4)
845 if err != nil {
846 return me.NewMessageTruncatedError(err.Error())
847 }
848 copy(remainingBytes, lotsOfZeros[:])
Matteo Scandolof9d43412021-01-12 11:11:34 -0800849
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700850 if omci.Result == me.AttributeFailure {
851 binary.BigEndian.PutUint16(remainingBytes[bytesLeft-4:bytesLeft-2], omci.UnsupportedAttributeMask)
852 binary.BigEndian.PutUint16(remainingBytes[bytesLeft-2:bytesLeft], omci.FailedAttributeMask)
853 }
854 }
855 return nil
856}
857
858/////////////////////////////////////////////////////////////////////////////
859// GetAllAlarms
860type GetAllAlarmsRequest struct {
861 MeBasePacket
862 AlarmRetrievalMode byte
863}
864
865func (omci *GetAllAlarmsRequest) String() string {
866 return fmt.Sprintf("%v, Retrieval Mode: %v",
867 omci.MeBasePacket.String(), omci.AlarmRetrievalMode)
868}
869
Matteo Scandolof9d43412021-01-12 11:11:34 -0800870// DecodeFromBytes decodes the given bytes of a Get All Alarms Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700871func (omci *GetAllAlarmsRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
872 // Common ClassID/EntityID decode in msgBase
873 err := omci.MeBasePacket.DecodeFromBytes(data, p)
874 if err != nil {
875 return err
876 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800877 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700878 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800879 if omciErr.StatusCode() != me.Success {
880 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700881 }
882 // ME needs to support Get All Alarms
883 if !me.SupportsMsgType(meDefinition, me.GetAllAlarms) {
884 return me.NewProcessingError("managed entity does not support Get All Alarms Message-Type")
885 }
886 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -0800887 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700888 msg := fmt.Sprintf("invalid Entity Class for Get All Alarms request: %v",
889 omci.EntityClass)
890 return me.NewProcessingError(msg)
891 }
892 if omci.EntityInstance != 0 {
893 msg := fmt.Sprintf("invalid Entity Instance for Get All Alarms request: %v",
894 omci.EntityInstance)
895 return me.NewUnknownInstanceError(msg)
896 }
897 omci.AlarmRetrievalMode = data[4]
898 if omci.AlarmRetrievalMode > 1 {
899 msg := fmt.Sprintf("invalid Alarm Retrieval Mode for Get All Alarms request: %v, must be 0..1",
900 omci.AlarmRetrievalMode)
901 return errors.New(msg)
902 }
903 return nil
904}
905
906func decodeGetAllAlarmsRequest(data []byte, p gopacket.PacketBuilder) error {
907 omci := &GetAllAlarmsRequest{}
908 omci.MsgLayerType = LayerTypeGetAllAlarmsRequest
909 return decodingLayerDecoder(omci, data, p)
910}
911
Matteo Scandolof9d43412021-01-12 11:11:34 -0800912// SerializeTo provides serialization of an Get All Alarms Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700913func (omci *GetAllAlarmsRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
914 // Basic (common) OMCI Header is 8 octets, 10
915 err := omci.MeBasePacket.SerializeTo(b)
916 if err != nil {
917 return err
918 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800919 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700920 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800921 if omciErr.StatusCode() != me.Success {
922 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700923 }
924 // ME needs to support Get All Alarms
925 if !me.SupportsMsgType(entity, me.GetAllAlarms) {
926 return me.NewProcessingError("managed entity does not support the Get All Alarms Message-Type")
927 }
928 bytes, err := b.AppendBytes(1)
929 if err != nil {
930 return err
931 }
932 bytes[0] = omci.AlarmRetrievalMode
933 return nil
934}
935
936/////////////////////////////////////////////////////////////////////////////
937// GetAllAlarms
938type GetAllAlarmsResponse struct {
939 MeBasePacket
940 NumberOfCommands uint16
941}
942
943func (omci *GetAllAlarmsResponse) String() string {
944 return fmt.Sprintf("%v, NumberOfCommands: %d",
945 omci.MeBasePacket.String(), omci.NumberOfCommands)
946}
947
Matteo Scandolof9d43412021-01-12 11:11:34 -0800948// DecodeFromBytes decodes the given bytes of a Get All Alarms Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700949func (omci *GetAllAlarmsResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
950 // Common ClassID/EntityID decode in msgBase
951 err := omci.MeBasePacket.DecodeFromBytes(data, p)
952 if err != nil {
953 return err
954 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800955 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700956 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800957 if omciErr.StatusCode() != me.Success {
958 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700959 }
960 // ME needs to support Get All Alarms
961 if !me.SupportsMsgType(meDefinition, me.GetAllAlarms) {
962 return me.NewProcessingError("managed entity does not support Get All Alarms Message-Type")
963 }
964 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -0800965 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700966 msg := fmt.Sprintf("invalid Entity Class for Get All Alarms response: %v",
967 omci.EntityClass)
968 return me.NewProcessingError(msg)
969 }
970 if omci.EntityInstance != 0 {
971 msg := fmt.Sprintf("invalid Entity Instance for Get All Alarms response: %v",
972 omci.EntityInstance)
973 return me.NewUnknownInstanceError(msg)
974 }
975 omci.NumberOfCommands = binary.BigEndian.Uint16(data[4:6])
976 return nil
977}
978
979func decodeGetAllAlarmsResponse(data []byte, p gopacket.PacketBuilder) error {
980 omci := &GetAllAlarmsResponse{}
981 omci.MsgLayerType = LayerTypeGetAllAlarmsResponse
982 return decodingLayerDecoder(omci, data, p)
983}
984
Matteo Scandolof9d43412021-01-12 11:11:34 -0800985// SerializeTo provides serialization of an Get All Alarms Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700986func (omci *GetAllAlarmsResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
987 // Basic (common) OMCI Header is 8 octets, 10
988 err := omci.MeBasePacket.SerializeTo(b)
989 if err != nil {
990 return err
991 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800992 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700993 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800994 if omciErr.StatusCode() != me.Success {
995 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700996 }
997 // ME needs to support Get All Alarms
998 if !me.SupportsMsgType(entity, me.GetAllAlarms) {
999 return me.NewProcessingError("managed entity does not support the Get All Alarms Message-Type")
1000 }
1001 bytes, err := b.AppendBytes(2)
1002 if err != nil {
1003 return err
1004 }
1005 binary.BigEndian.PutUint16(bytes[0:2], omci.NumberOfCommands)
1006 return nil
1007}
1008
1009/////////////////////////////////////////////////////////////////////////////
1010// GetAllAlarms
1011type GetAllAlarmsNextRequest struct {
1012 MeBasePacket
1013 CommandSequenceNumber uint16
1014}
1015
1016func (omci *GetAllAlarmsNextRequest) String() string {
1017 return fmt.Sprintf("%v, Sequence Number: %d",
1018 omci.MeBasePacket.String(), omci.CommandSequenceNumber)
1019}
1020
Matteo Scandolof9d43412021-01-12 11:11:34 -08001021// DecodeFromBytes decodes the given bytes of a Get All Alarms Next Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001022func (omci *GetAllAlarmsNextRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1023 // Common ClassID/EntityID decode in msgBase
1024 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1025 if err != nil {
1026 return err
1027 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001028 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001029 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001030 if omciErr.StatusCode() != me.Success {
1031 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001032 }
1033 // ME needs to support Get All Alarms
1034 if !me.SupportsMsgType(meDefinition, me.GetAllAlarmsNext) {
1035 return me.NewProcessingError("managed entity does not support Get All Alarms Next Message-Type")
1036 }
1037 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08001038 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001039 msg := fmt.Sprintf("invalid Entity Class for Get All Alarms Next request: %v",
1040 omci.EntityClass)
1041 return me.NewProcessingError(msg)
1042 }
1043 if omci.EntityInstance != 0 {
1044 msg := fmt.Sprintf("invalid Entity Instance for Get All Alarms Next request: %v",
1045 omci.EntityInstance)
1046 return me.NewUnknownInstanceError(msg)
1047 }
1048 omci.CommandSequenceNumber = binary.BigEndian.Uint16(data[4:6])
1049 return nil
1050}
1051
1052func decodeGetAllAlarmsNextRequest(data []byte, p gopacket.PacketBuilder) error {
1053 omci := &GetAllAlarmsNextRequest{}
1054 omci.MsgLayerType = LayerTypeGetAllAlarmsNextRequest
1055 return decodingLayerDecoder(omci, data, p)
1056}
1057
Matteo Scandolof9d43412021-01-12 11:11:34 -08001058// SerializeTo provides serialization of an Get All Alarms Next Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001059func (omci *GetAllAlarmsNextRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1060 // Basic (common) OMCI Header is 8 octets, 10
1061 err := omci.MeBasePacket.SerializeTo(b)
1062 if err != nil {
1063 return err
1064 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001065 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001066 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001067 if omciErr.StatusCode() != me.Success {
1068 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001069 }
1070 // ME needs to support Get All Alarms Next
1071 if !me.SupportsMsgType(entity, me.GetAllAlarmsNext) {
1072 return me.NewProcessingError("managed entity does not support the Get All Alarms Next Message-Type")
1073 }
1074 bytes, err := b.AppendBytes(2)
1075 if err != nil {
1076 return err
1077 }
1078 binary.BigEndian.PutUint16(bytes, omci.CommandSequenceNumber)
1079 return nil
1080}
1081
1082/////////////////////////////////////////////////////////////////////////////
1083// GetAllAlarms
1084type GetAllAlarmsNextResponse struct {
1085 MeBasePacket
1086 AlarmEntityClass me.ClassID
1087 AlarmEntityInstance uint16
1088 AlarmBitMap [28]byte // 224 bits
1089}
1090
1091func (omci *GetAllAlarmsNextResponse) String() string {
1092 return fmt.Sprintf("%v, CID: %v, EID: (%d/%#x), Bitmap: %v",
1093 omci.MeBasePacket.String(), omci.AlarmEntityClass, omci.AlarmEntityInstance,
1094 omci.AlarmEntityInstance, omci.AlarmBitMap)
1095}
1096
Matteo Scandolof9d43412021-01-12 11:11:34 -08001097// DecodeFromBytes decodes the given bytes of a Get All Alarms Next Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001098func (omci *GetAllAlarmsNextResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1099 // Common ClassID/EntityID decode in msgBase
1100 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1101 if err != nil {
1102 return err
1103 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001104 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001105 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001106 if omciErr.StatusCode() != me.Success {
1107 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001108 }
1109 // ME needs to support Get All Alarms Next
1110 if !me.SupportsMsgType(meDefinition, me.GetAllAlarmsNext) {
1111 return me.NewProcessingError("managed entity does not support Get All Alarms Next Message-Type")
1112 }
1113 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08001114 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001115 msg := fmt.Sprintf("invalid Entity Class for Get All Alarms Next response: %v",
1116 omci.EntityClass)
1117 return me.NewProcessingError(msg)
1118 }
1119 if omci.EntityInstance != 0 {
1120 msg := fmt.Sprintf("invalid Entity Instance for Get All Alarms Next response: %v",
1121 omci.EntityInstance)
1122 return me.NewUnknownInstanceError(msg)
1123 }
1124 omci.AlarmEntityClass = me.ClassID(binary.BigEndian.Uint16(data[4:6]))
1125 omci.AlarmEntityInstance = binary.BigEndian.Uint16(data[6:8])
1126
1127 copy(omci.AlarmBitMap[:], data[8:36])
1128 return nil
1129}
1130
1131func decodeGetAllAlarmsNextResponse(data []byte, p gopacket.PacketBuilder) error {
1132 omci := &GetAllAlarmsNextResponse{}
1133 omci.MsgLayerType = LayerTypeGetAllAlarmsNextResponse
1134 return decodingLayerDecoder(omci, data, p)
1135}
1136
Matteo Scandolof9d43412021-01-12 11:11:34 -08001137// SerializeTo provides serialization of an Get All Alarms Next Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001138func (omci *GetAllAlarmsNextResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1139 // Basic (common) OMCI Header is 8 octets, 10
1140 err := omci.MeBasePacket.SerializeTo(b)
1141 if err != nil {
1142 return err
1143 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001144 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001145 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001146 if omciErr.StatusCode() != me.Success {
1147 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001148 }
1149 // ME needs to support Get All Alarms Next
1150 if !me.SupportsMsgType(entity, me.GetAllAlarmsNext) {
1151 return me.NewProcessingError("managed entity does not support the Get All Alarms Next Message-Type")
1152 }
1153 bytes, err := b.AppendBytes(2 + 2 + 28)
1154 if err != nil {
1155 return err
1156 }
1157 binary.BigEndian.PutUint16(bytes[0:], uint16(omci.AlarmEntityClass))
1158 binary.BigEndian.PutUint16(bytes[2:], omci.AlarmEntityInstance)
1159 copy(bytes[4:], omci.AlarmBitMap[:])
1160 return nil
1161}
1162
1163/////////////////////////////////////////////////////////////////////////////
1164// MibUploadRequest
1165type MibUploadRequest struct {
1166 MeBasePacket
1167}
1168
1169func (omci *MibUploadRequest) String() string {
1170 return fmt.Sprintf("%v", omci.MeBasePacket.String())
1171}
1172
Matteo Scandolof9d43412021-01-12 11:11:34 -08001173// DecodeFromBytes decodes the given bytes of a MIB Upload Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001174func (omci *MibUploadRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1175 // Common ClassID/EntityID decode in msgBase
1176 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1177 if err != nil {
1178 return err
1179 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001180 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001181 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001182 if omciErr.StatusCode() != me.Success {
1183 return omciErr.GetError()
1184 }
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001185 // ME needs to support MIB Upload
1186 if !me.SupportsMsgType(meDefinition, me.MibUpload) {
1187 return me.NewProcessingError("managed entity does not support MIB Upload Message-Type")
1188 }
1189 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08001190 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001191 msg := fmt.Sprintf("invalid Entity Class for MIB Upload request: %v",
1192 omci.EntityClass)
1193 return me.NewProcessingError(msg)
1194 }
1195 if omci.EntityInstance != 0 {
1196 msg := fmt.Sprintf("invalid Entity Instance for MIB Upload request: %v",
1197 omci.EntityInstance)
1198 return me.NewUnknownInstanceError(msg)
1199 }
1200 return nil
1201}
1202
1203func decodeMibUploadRequest(data []byte, p gopacket.PacketBuilder) error {
1204 omci := &MibUploadRequest{}
1205 omci.MsgLayerType = LayerTypeMibUploadRequest
1206 return decodingLayerDecoder(omci, data, p)
1207}
1208
Matteo Scandolof9d43412021-01-12 11:11:34 -08001209// SerializeTo provides serialization of an MIB Upload Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001210func (omci *MibUploadRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1211 // Basic (common) OMCI Header is 8 octets, 10
1212 err := omci.MeBasePacket.SerializeTo(b)
1213 if err != nil {
1214 return err
1215 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001216 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001217 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001218 if omciErr.StatusCode() != me.Success {
1219 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001220 }
1221 // ME needs to support Get
1222 if !me.SupportsMsgType(meDefinition, me.MibUpload) {
1223 return me.NewProcessingError("managed entity does not support the MIB Upload Message-Type")
1224 }
1225 return nil
1226}
1227
1228/////////////////////////////////////////////////////////////////////////////
1229// MibUploadResponse
1230type MibUploadResponse struct {
1231 MeBasePacket
1232 NumberOfCommands uint16
1233}
1234
1235func (omci *MibUploadResponse) String() string {
1236 return fmt.Sprintf("%v, NumberOfCommands: %#v",
1237 omci.MeBasePacket.String(), omci.NumberOfCommands)
1238}
1239
Matteo Scandolof9d43412021-01-12 11:11:34 -08001240// DecodeFromBytes decodes the given bytes of a MIB Upload Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001241func (omci *MibUploadResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1242 // Common ClassID/EntityID decode in msgBase
1243 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1244 if err != nil {
1245 return err
1246 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001247 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001248 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001249 if omciErr.StatusCode() != me.Success {
1250 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001251 }
1252 // ME needs to support MIB Upload
1253 if !me.SupportsMsgType(meDefinition, me.MibUpload) {
1254 return me.NewProcessingError("managed entity does not support MIB Upload Message-Type")
1255 }
1256 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08001257 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001258 msg := fmt.Sprintf("invalid Entity Class for MIB Upload response: %v",
1259 omci.EntityClass)
1260 return me.NewProcessingError(msg)
1261 }
1262 if omci.EntityInstance != 0 {
1263 msg := fmt.Sprintf("invalid Entity Instance for MIB Upload response: %v",
1264 omci.EntityInstance)
1265 return me.NewUnknownInstanceError(msg)
1266 }
1267 omci.NumberOfCommands = binary.BigEndian.Uint16(data[4:6])
1268 return nil
1269}
1270
1271func decodeMibUploadResponse(data []byte, p gopacket.PacketBuilder) error {
1272 omci := &MibUploadResponse{}
1273 omci.MsgLayerType = LayerTypeMibUploadResponse
1274 return decodingLayerDecoder(omci, data, p)
1275}
1276
Matteo Scandolof9d43412021-01-12 11:11:34 -08001277// SerializeTo provides serialization of an MIB Upload Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001278func (omci *MibUploadResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1279 // Basic (common) OMCI Header is 8 octets, 10
1280 err := omci.MeBasePacket.SerializeTo(b)
1281 if err != nil {
1282 return err
1283 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001284 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001285 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001286 if omciErr.StatusCode() != me.Success {
1287 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001288 }
1289 // ME needs to support MIB Upload
1290 if !me.SupportsMsgType(entity, me.MibUpload) {
1291 return me.NewProcessingError("managed entity does not support the MIB Upload Message-Type")
1292 }
1293 bytes, err := b.AppendBytes(2)
1294 if err != nil {
1295 return err
1296 }
1297 binary.BigEndian.PutUint16(bytes[0:2], omci.NumberOfCommands)
1298 return nil
1299}
1300
1301/////////////////////////////////////////////////////////////////////////////
1302//
1303type MibUploadNextRequest struct {
1304 MeBasePacket
1305 CommandSequenceNumber uint16
1306}
1307
1308func (omci *MibUploadNextRequest) String() string {
1309 return fmt.Sprintf("%v, SequenceNumberCountOrSize: %v",
1310 omci.MeBasePacket.String(), omci.CommandSequenceNumber)
1311}
1312
Matteo Scandolof9d43412021-01-12 11:11:34 -08001313// DecodeFromBytes decodes the given bytes of a MIB Upload Next Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001314func (omci *MibUploadNextRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1315 // Common ClassID/EntityID decode in msgBase
1316 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1317 if err != nil {
1318 return err
1319 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001320 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001321 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001322 if omciErr.StatusCode() != me.Success {
1323 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001324 }
1325 // ME needs to support Get All Alarms
1326 if !me.SupportsMsgType(meDefinition, me.MibUploadNext) {
1327 return me.NewProcessingError("managed entity does not support MIB Upload Next Message-Type")
1328 }
1329 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08001330 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001331 msg := fmt.Sprintf("invalid Entity Class for MIB Upload Next request: %v",
1332 omci.EntityClass)
1333 return me.NewProcessingError(msg)
1334 }
1335 if omci.EntityInstance != 0 {
1336 msg := fmt.Sprintf("invalid Entity Instance for MIB Upload Next request: %v",
1337 omci.EntityInstance)
1338 return me.NewUnknownInstanceError(msg)
1339 }
1340 omci.CommandSequenceNumber = binary.BigEndian.Uint16(data[4:6])
1341 return nil
1342}
1343
1344func decodeMibUploadNextRequest(data []byte, p gopacket.PacketBuilder) error {
1345 omci := &MibUploadNextRequest{}
1346 omci.MsgLayerType = LayerTypeMibUploadNextRequest
1347 return decodingLayerDecoder(omci, data, p)
1348}
1349
Matteo Scandolof9d43412021-01-12 11:11:34 -08001350// SerializeTo provides serialization of an MIB Upload Next Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001351func (omci *MibUploadNextRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1352 // Basic (common) OMCI Header is 8 octets, 10
1353 err := omci.MeBasePacket.SerializeTo(b)
1354 if err != nil {
1355 return err
1356 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001357 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001358 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001359 if omciErr.StatusCode() != me.Success {
1360 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001361 }
1362 // ME needs to support MIB upload
1363 if !me.SupportsMsgType(entity, me.MibUploadNext) {
1364 return me.NewProcessingError("managed entity does not support the MIB Upload Next Message-Type")
1365 }
1366 bytes, err := b.AppendBytes(2)
1367 if err != nil {
1368 return err
1369 }
1370 binary.BigEndian.PutUint16(bytes[0:2], omci.CommandSequenceNumber)
1371 return nil
1372}
1373
1374/////////////////////////////////////////////////////////////////////////////
1375//
1376type MibUploadNextResponse struct {
1377 MeBasePacket
1378 ReportedME me.ManagedEntity
1379}
1380
1381func (omci *MibUploadNextResponse) String() string {
1382 return fmt.Sprintf("%v, ReportedME: [%v]",
1383 omci.MeBasePacket.String(), omci.ReportedME.String())
1384}
1385
Matteo Scandolof9d43412021-01-12 11:11:34 -08001386// DecodeFromBytes decodes the given bytes of a MIB Upload Next Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001387func (omci *MibUploadNextResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1388 // Common ClassID/EntityID decode in msgBase
1389 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1390 if err != nil {
1391 return err
1392 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001393 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001394 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001395 if omciErr.StatusCode() != me.Success {
1396 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001397 }
1398 // ME needs to support MibUploadNext
1399 if !me.SupportsMsgType(meDefinition, me.MibUploadNext) {
1400 return me.NewProcessingError("managed entity does not support MIB Upload Next Message-Type")
1401 }
1402 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08001403 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001404 msg := fmt.Sprintf("invalid Entity Class for MIB Upload Next response: %v",
1405 omci.EntityClass)
1406 return me.NewProcessingError(msg)
1407 }
1408 if omci.EntityInstance != 0 {
1409 msg := fmt.Sprintf("invalid Entity Instance for MIB Upload Next response: %v",
1410 omci.EntityInstance)
1411 return me.NewUnknownInstanceError(msg)
1412 }
1413 // Decode reported ME. If an out-of-range sequence number was sent, this will
1414 // contain an ME with class ID and entity ID of zero and you should get an
1415 // error of "managed entity definition not found" returned.
1416 return omci.ReportedME.DecodeFromBytes(data[4:], p, byte(MibUploadNextResponseType))
1417}
1418
1419func decodeMibUploadNextResponse(data []byte, p gopacket.PacketBuilder) error {
1420 omci := &MibUploadNextResponse{}
1421 omci.MsgLayerType = LayerTypeMibUploadNextResponse
1422 return decodingLayerDecoder(omci, data, p)
1423}
1424
Matteo Scandolof9d43412021-01-12 11:11:34 -08001425// SerializeTo provides serialization of an MIB Upload Next Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001426func (omci *MibUploadNextResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1427 // Basic (common) OMCI Header is 8 octets, 10
1428 err := omci.MeBasePacket.SerializeTo(b)
1429 if err != nil {
1430 return err
1431 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001432 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001433 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001434 if omciErr.StatusCode() != me.Success {
1435 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001436 }
1437 // ME needs to support MIB Upload
1438 if !me.SupportsMsgType(entity, me.MibUploadNext) {
1439 return me.NewProcessingError("managed entity does not support the MIB Upload Next Message-Type")
1440 }
1441 // TODO: Only Baseline supported at this time
1442 bytesAvailable := MaxBaselineLength - 8 - 8
1443
Matteo Scandolof9d43412021-01-12 11:11:34 -08001444 return omci.ReportedME.SerializeTo(b, byte(MibUploadNextResponseType), bytesAvailable, opts)
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001445}
1446
1447/////////////////////////////////////////////////////////////////////////////
1448// MibResetRequest
1449type MibResetRequest struct {
1450 MeBasePacket
1451}
1452
1453func (omci *MibResetRequest) String() string {
1454 return fmt.Sprintf("%v", omci.MeBasePacket.String())
1455}
1456
Matteo Scandolof9d43412021-01-12 11:11:34 -08001457// DecodeFromBytes decodes the given bytes of a MIB Reset Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001458func (omci *MibResetRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1459 // Common ClassID/EntityID decode in msgBase
1460 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1461 if err != nil {
1462 return err
1463 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001464 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001465 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001466 if omciErr.StatusCode() != me.Success {
1467 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001468 }
1469 // ME needs to support MIB reset
1470 if !me.SupportsMsgType(meDefinition, me.MibReset) {
1471 return me.NewProcessingError("managed entity does not support MIB Reset Message-Type")
1472 }
1473 // Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08001474 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001475 msg := fmt.Sprintf("invalid Entity Class for MIB Reset request: %v",
1476 omci.EntityClass)
1477 return me.NewProcessingError(msg)
1478 }
1479 if omci.EntityInstance != 0 {
1480 msg := fmt.Sprintf("invalid Entity Instance for MIB Reset request: %v",
1481 omci.EntityInstance)
1482 return me.NewUnknownInstanceError(msg)
1483 }
1484 return nil
1485}
1486
1487func decodeMibResetRequest(data []byte, p gopacket.PacketBuilder) error {
1488 omci := &MibResetRequest{}
1489 omci.MsgLayerType = LayerTypeMibResetRequest
1490 return decodingLayerDecoder(omci, data, p)
1491}
1492
Matteo Scandolof9d43412021-01-12 11:11:34 -08001493// SerializeTo provides serialization of an MIB Reset Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001494func (omci *MibResetRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1495 // Add class ID and entity ID
1496 return omci.MeBasePacket.SerializeTo(b)
1497}
1498
1499/////////////////////////////////////////////////////////////////////////////
1500// MibResetResponse
1501type MibResetResponse struct {
1502 MeBasePacket
1503 Result me.Results
1504}
1505
1506func (omci *MibResetResponse) String() string {
1507 return fmt.Sprintf("%v, Result: %d (%v)",
1508 omci.MeBasePacket.String(), omci.Result, omci.Result)
1509}
1510
Matteo Scandolof9d43412021-01-12 11:11:34 -08001511// DecodeFromBytes decodes the given bytes of a MIB Reset Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001512func (omci *MibResetResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1513 // Common ClassID/EntityID decode in msgBase
1514 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1515 if err != nil {
1516 return err
1517 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001518 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001519 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001520 if omciErr.StatusCode() != me.Success {
1521 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001522 }
1523 // ME needs to support MIB reset
1524 if !me.SupportsMsgType(meDefinition, me.MibReset) {
1525 return me.NewProcessingError("managed entity does not support MIB Reset Message-Type")
1526 }
1527 // MIB Reset Response Entity Class always ONU DATA (2) and
1528 // Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08001529 if omci.EntityClass != me.OnuDataClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001530 return me.NewProcessingError("invalid Entity Class for MIB Reset Response")
1531 }
1532 if omci.EntityInstance != 0 {
1533 return me.NewUnknownInstanceError("invalid Entity Instance for MIB Reset Response")
1534 }
1535 omci.Result = me.Results(data[4])
1536 if omci.Result > me.DeviceBusy {
1537 msg := fmt.Sprintf("invalid results code: %v, must be 0..8", omci.Result)
1538 return errors.New(msg)
1539 }
1540 return nil
1541}
1542
1543func decodeMibResetResponse(data []byte, p gopacket.PacketBuilder) error {
1544 omci := &MibResetResponse{}
1545 omci.MsgLayerType = LayerTypeMibResetResponse
1546 return decodingLayerDecoder(omci, data, p)
1547}
1548
Matteo Scandolof9d43412021-01-12 11:11:34 -08001549// SerializeTo provides serialization of an MIB Reset Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001550func (omci *MibResetResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1551 // Basic (common) OMCI Header is 8 octets, 10
1552 err := omci.MeBasePacket.SerializeTo(b)
1553 if err != nil {
1554 return err
1555 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001556 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001557 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001558 if omciErr.StatusCode() != me.Success {
1559 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001560 }
1561 // ME needs to support Set
1562 if !me.SupportsMsgType(entity, me.MibReset) {
1563 return me.NewProcessingError("managed entity does not support the MIB Reset Message-Type")
1564 }
1565 bytes, err := b.AppendBytes(1)
1566 if err != nil {
1567 return err
1568 }
1569 bytes[0] = byte(omci.Result)
1570 return nil
1571}
1572
1573/////////////////////////////////////////////////////////////////////////////
1574// AlarmNotificationMsg
1575const AlarmBitmapSize = 224
1576
1577type AlarmNotificationMsg struct {
1578 MeBasePacket
1579 AlarmBitmap [AlarmBitmapSize / 8]byte
1580 zeroPadding [3]byte
1581 AlarmSequenceNumber byte
1582}
1583
1584func (omci *AlarmNotificationMsg) String() string {
1585 return fmt.Sprintf("%v, Sequence Number: %d, Alarm Bitmap: %v",
1586 omci.MeBasePacket.String(), omci.AlarmSequenceNumber, omci.AlarmBitmap)
1587}
1588
1589func (omci *AlarmNotificationMsg) IsAlarmActive(alarmNumber uint8) (bool, error) {
1590 if alarmNumber >= AlarmBitmapSize {
1591 msg := fmt.Sprintf("invalid alarm number: %v, must be 0..224", alarmNumber)
1592 return false, errors.New(msg)
1593 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001594 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
1595 me.ParamData{EntityID: omci.EntityInstance})
1596 if omciErr.StatusCode() != me.Success {
1597 return false, omciErr.GetError()
1598 }
1599 alarmMap := entity.GetAlarmMap()
1600 if alarmMap == nil {
1601 msg := "Managed Entity does not support Alarm notifications"
1602 return false, errors.New(msg)
1603 }
1604 if _, ok := alarmMap[alarmNumber]; !ok {
1605 msg := fmt.Sprintf("unsupported invalid alarm number: %v", alarmNumber)
1606 return false, errors.New(msg)
1607 }
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001608 octet := alarmNumber / 8
1609 bit := 7 - (alarmNumber % 8)
1610 return omci.AlarmBitmap[octet]>>bit == 1, nil
1611}
1612
1613func (omci *AlarmNotificationMsg) IsAlarmClear(alarmNumber uint8) (bool, error) {
1614 if alarmNumber >= AlarmBitmapSize {
1615 msg := fmt.Sprintf("invalid alarm number: %v, must be 0..224", alarmNumber)
1616 return false, errors.New(msg)
1617 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001618 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
1619 me.ParamData{EntityID: omci.EntityInstance})
1620 if omciErr.StatusCode() != me.Success {
1621 return false, omciErr.GetError()
1622 }
1623 alarmMap := entity.GetAlarmMap()
1624 if alarmMap == nil {
1625 return false, errors.New("Managed Entity does not support Alarm notifications")
1626 }
1627 if _, ok := alarmMap[alarmNumber]; !ok {
1628 msg := fmt.Sprintf("unsupported invalid alarm number: %v", alarmNumber)
1629 return false, errors.New(msg)
1630 }
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001631 octet := alarmNumber / 8
1632 bit := 7 - (alarmNumber % 8)
1633 return omci.AlarmBitmap[octet]>>bit == 0, nil
1634}
1635
1636func (omci *AlarmNotificationMsg) ActivateAlarm(alarmNumber uint8) error {
1637 if alarmNumber >= AlarmBitmapSize {
1638 msg := fmt.Sprintf("invalid alarm number: %v, must be 0..224", alarmNumber)
1639 return errors.New(msg)
1640 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001641 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
1642 me.ParamData{EntityID: omci.EntityInstance})
1643 if omciErr.StatusCode() != me.Success {
1644 return omciErr.GetError()
1645 }
1646 alarmMap := entity.GetAlarmMap()
1647 if alarmMap == nil {
1648 return errors.New("Managed Entity does not support Alarm notifications")
1649 }
1650 if _, ok := alarmMap[alarmNumber]; !ok {
1651 msg := fmt.Sprintf("unsupported invalid alarm number: %v", alarmNumber)
1652 return errors.New(msg)
1653 }
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001654 octet := alarmNumber / 8
1655 bit := 7 - (alarmNumber % 8)
1656 omci.AlarmBitmap[octet] |= 1 << bit
1657 return nil
1658}
1659
1660func (omci *AlarmNotificationMsg) ClearAlarm(alarmNumber uint8) error {
1661 if alarmNumber >= AlarmBitmapSize {
1662 msg := fmt.Sprintf("invalid alarm number: %v, must be 0..224", alarmNumber)
1663 return errors.New(msg)
1664 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001665 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
1666 me.ParamData{EntityID: omci.EntityInstance})
1667 if omciErr.StatusCode() != me.Success {
1668 return omciErr.GetError()
1669 }
1670 alarmMap := entity.GetAlarmMap()
1671 if alarmMap == nil {
1672 return errors.New("Managed Entity does not support Alarm notifications")
1673 }
1674 if _, ok := alarmMap[alarmNumber]; !ok {
1675 msg := fmt.Sprintf("unsupported invalid alarm number: %v", alarmNumber)
1676 return errors.New(msg)
1677 }
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001678 octet := alarmNumber / 8
1679 bit := 7 - (alarmNumber % 8)
1680 omci.AlarmBitmap[octet] &= ^(1 << bit)
1681 return nil
1682}
1683
Matteo Scandolof9d43412021-01-12 11:11:34 -08001684// DecodeFromBytes decodes the given bytes of an Alarm Notification into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001685func (omci *AlarmNotificationMsg) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1686 // Common ClassID/EntityID decode in msgBase
1687 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1688 if err != nil {
1689 return err
1690 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001691 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
1692 me.ParamData{EntityID: omci.EntityInstance})
1693 if omciErr.StatusCode() != me.Success {
1694 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001695 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001696 // Is this an unsupported or vendor specific ME. If so, it is not an error to decode
1697 // the alarms. We just cannot provide any alarm names. Handle decode here.
1698 classSupport := meDefinition.GetClassSupport()
1699 isUnsupported := classSupport == me.UnsupportedManagedEntity ||
1700 classSupport == me.UnsupportedVendorSpecificManagedEntity
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001701
Matteo Scandolof9d43412021-01-12 11:11:34 -08001702 // Look for a non-nil/not empty Alarm Map to determine if this ME supports alarms
1703 if alarmMap := meDefinition.GetAlarmMap(); isUnsupported || (alarmMap != nil && len(alarmMap) > 0) {
1704 for index, octet := range data[4 : (AlarmBitmapSize/8)-4] {
1705 omci.AlarmBitmap[index] = octet
1706 }
1707 padOffset := 4 + (AlarmBitmapSize / 8)
1708 omci.zeroPadding[0] = data[padOffset]
1709 omci.zeroPadding[1] = data[padOffset+1]
1710 omci.zeroPadding[2] = data[padOffset+2]
1711
1712 omci.AlarmSequenceNumber = data[padOffset+3]
1713 return nil
1714 }
1715 return me.NewProcessingError("managed entity does not support alarm notifications")
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001716}
1717
1718func decodeAlarmNotification(data []byte, p gopacket.PacketBuilder) error {
1719 omci := &AlarmNotificationMsg{}
1720 omci.MsgLayerType = LayerTypeAlarmNotification
1721 return decodingLayerDecoder(omci, data, p)
1722}
1723
Matteo Scandolof9d43412021-01-12 11:11:34 -08001724// SerializeTo provides serialization of an Alarm Notification message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001725func (omci *AlarmNotificationMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1726 // Basic (common) OMCI Header is 8 octets, 10
1727 err := omci.MeBasePacket.SerializeTo(b)
1728 if err != nil {
1729 return err
1730 }
1731 //var meDefinition me.IManagedEntityDefinition
1732 //meDefinition, err = me.LoadManagedEntityDefinition(omci.EntityClass,
1733 // me.ParamData{EntityID: omci.EntityInstance})
1734 //if err != nil {
1735 // return err
1736 //}
1737 // ME needs to support Alarms
1738 // TODO: Add attribute to ME to specify that alarm is allowed
1739 //if !me.SupportsMsgType(meDefinition, me.MibReset) {
1740 // return me.NewProcessingError("managed entity does not support MIB Reset Message-Type")
1741 //}
1742 bytes, err := b.AppendBytes((AlarmBitmapSize / 8) + 3 + 1)
1743 if err != nil {
1744 return err
1745 }
1746 for index, octet := range omci.AlarmBitmap {
1747 bytes[index] = octet
1748 }
1749 padOffset := AlarmBitmapSize / 8
1750 bytes[padOffset] = 0
1751 bytes[padOffset+1] = 0
1752 bytes[padOffset+2] = 0
1753 bytes[padOffset+3] = omci.AlarmSequenceNumber
1754 return nil
1755}
1756
1757/////////////////////////////////////////////////////////////////////////////
1758// AttributeValueChangeMsg
1759type AttributeValueChangeMsg struct {
1760 MeBasePacket
1761 AttributeMask uint16
1762 Attributes me.AttributeValueMap
1763}
1764
1765func (omci *AttributeValueChangeMsg) String() string {
1766 return fmt.Sprintf("%v, Mask: %#x, attributes: %v",
1767 omci.MeBasePacket.String(), omci.AttributeMask, omci.Attributes)
1768}
1769
Matteo Scandolof9d43412021-01-12 11:11:34 -08001770// DecodeFromBytes decodes the given bytes of an Attribute Value Change notification into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001771func (omci *AttributeValueChangeMsg) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1772 // Common ClassID/EntityID decode in msgBase
1773 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1774 if err != nil {
1775 return err
1776 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001777 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001778 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001779 if omciErr.StatusCode() != me.Success {
1780 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001781 }
1782 omci.AttributeMask = binary.BigEndian.Uint16(data[4:6])
1783 // Attribute decode
1784 omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[6:40], p, byte(AttributeValueChangeType))
1785 // TODO: Add support for attributes that can have an AVC associated with them and then add a check here
1786 // Validate all attributes support AVC
1787 //for attrName := range omci.attributes {
1788 // attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
1789 // if err != nil {
1790 // return err
1791 // }
1792 // if attr.Index != 0 && !me.SupportsAttributeAVC(attr) {
1793 // msg := fmt.Sprintf("attribute '%v' does not support AVC notifications", attrName)
1794 // return me.NewProcessingError(msg)
1795 // }
1796 //}
1797 return err
1798}
1799
1800func decodeAttributeValueChange(data []byte, p gopacket.PacketBuilder) error {
1801 omci := &AttributeValueChangeMsg{}
1802 omci.MsgLayerType = LayerTypeAttributeValueChange
1803 return decodingLayerDecoder(omci, data, p)
1804}
1805
Matteo Scandolof9d43412021-01-12 11:11:34 -08001806// SerializeTo provides serialization of an Attribute Value Change Notification message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001807func (omci *AttributeValueChangeMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1808 // Basic (common) OMCI Header is 8 octets, 10
1809 err := omci.MeBasePacket.SerializeTo(b)
1810 if err != nil {
1811 return err
1812 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001813 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001814 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001815 if omciErr.StatusCode() != me.Success {
1816 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001817 }
1818 // TODO: Add support for attributes that can have an AVC associated with them and then add a check here
1819 // Validate all attributes support AVC
1820 //for attrName := range omci.attributes {
1821 // attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
1822 // if err != nil {
1823 // return err
1824 // }
1825 // if attr.Index != 0 && !me.SupportsAttributeAVC(attr) {
1826 // msg := fmt.Sprintf("attribute '%v' does not support AVC notifications", attrName)
1827 // return me.NewProcessingError(msg)
1828 // }
1829 //}
1830 bytes, err := b.AppendBytes(2)
1831 if err != nil {
1832 return err
1833 }
1834 binary.BigEndian.PutUint16(bytes, omci.AttributeMask)
1835
1836 // Attribute serialization
1837 // TODO: Only Baseline supported at this time
1838 bytesAvailable := MaxBaselineLength - 10 - 8
1839
Matteo Scandolof9d43412021-01-12 11:11:34 -08001840 err, _ = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b,
1841 byte(AttributeValueChangeType), bytesAvailable, false)
1842 return err
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001843}
1844
1845/////////////////////////////////////////////////////////////////////////////
1846// TestRequest: TODO: Not yet implemented
1847type TestRequest struct {
1848 MeBasePacket
1849}
1850
1851func (omci *TestRequest) String() string {
1852 return fmt.Sprintf("%v", omci.MeBasePacket.String())
1853}
1854
Matteo Scandolof9d43412021-01-12 11:11:34 -08001855// DecodeFromBytes decodes the given bytes of a Test Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001856func (omci *TestRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1857 // Common ClassID/EntityID decode in msgBase
1858 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1859 if err != nil {
1860 return err
1861 }
1862 return errors.New("need to implement") // TODO: Fix me) // return nil
1863}
1864
1865func decodeTestRequest(data []byte, p gopacket.PacketBuilder) error {
1866 omci := &TestRequest{}
1867 omci.MsgLayerType = LayerTypeTestRequest
1868 return decodingLayerDecoder(omci, data, p)
1869}
1870
Matteo Scandolof9d43412021-01-12 11:11:34 -08001871// SerializeTo provides serialization of an Test Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001872func (omci *TestRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1873 // Basic (common) OMCI Header is 8 octets, 10
1874 err := omci.MeBasePacket.SerializeTo(b)
1875 if err != nil {
1876 return err
1877 }
1878 return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b)
1879}
1880
1881/////////////////////////////////////////////////////////////////////////////
1882// TestResponse: TODO: Not yet implemented
1883type TestResponse struct {
1884 MeBasePacket
1885}
1886
1887func (omci *TestResponse) String() string {
1888 return fmt.Sprintf("%v", omci.MeBasePacket.String())
1889}
1890
Matteo Scandolof9d43412021-01-12 11:11:34 -08001891// DecodeFromBytes decodes the given bytes of a Test Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001892func (omci *TestResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1893 // Common ClassID/EntityID decode in msgBase
1894 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1895 if err != nil {
1896 return err
1897 }
1898 return errors.New("need to implement") // TODO: Fix me) // return nil
1899}
1900
1901func decodeTestResponse(data []byte, p gopacket.PacketBuilder) error {
1902 omci := &TestResponse{}
1903 omci.MsgLayerType = LayerTypeTestResponse
1904 return decodingLayerDecoder(omci, data, p)
1905}
1906
Matteo Scandolof9d43412021-01-12 11:11:34 -08001907// SerializeTo provides serialization of an Test Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001908func (omci *TestResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1909 // Basic (common) OMCI Header is 8 octets, 10
1910 err := omci.MeBasePacket.SerializeTo(b)
1911 if err != nil {
1912 return err
1913 }
1914 return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b)
1915}
1916
1917/////////////////////////////////////////////////////////////////////////////
1918//
1919type StartSoftwareDownloadRequest struct {
1920 MeBasePacket // Note: EntityInstance for software download is two specific values
1921 WindowSize byte // Window Size -1
1922 ImageSize uint32 // Octets
1923 NumberOfCircuitPacks byte
1924 CircuitPacks []uint16 // MSB & LSB of software image instance
1925}
1926
1927func (omci *StartSoftwareDownloadRequest) String() string {
1928 return fmt.Sprintf("%v, Window Size: %v, Image Size: %v, # Circuit Packs: %v",
1929 omci.MeBasePacket.String(), omci.WindowSize, omci.ImageSize, omci.NumberOfCircuitPacks)
1930}
1931
Matteo Scandolof9d43412021-01-12 11:11:34 -08001932// DecodeFromBytes decodes the given bytes of a Start Software Download Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001933func (omci *StartSoftwareDownloadRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
1934 err := omci.MeBasePacket.DecodeFromBytes(data, p)
1935 if err != nil {
1936 return err
1937 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001938 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001939 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001940 if omciErr.StatusCode() != me.Success {
1941 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001942 }
1943 // ME needs to support Start Software Download
1944 if !me.SupportsMsgType(meDefinition, me.StartSoftwareDownload) {
1945 return me.NewProcessingError("managed entity does not support Start Software Download Message-Type")
1946 }
1947 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08001948 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001949 return me.NewProcessingError("invalid Entity Class for Start Software Download request")
1950 }
1951 omci.WindowSize = data[4]
1952 omci.ImageSize = binary.BigEndian.Uint32(data[5:9])
1953 omci.NumberOfCircuitPacks = data[9]
1954 if omci.NumberOfCircuitPacks < 1 || omci.NumberOfCircuitPacks > 9 {
Matteo Scandolof9d43412021-01-12 11:11:34 -08001955 return me.NewProcessingError(fmt.Sprintf("invalid number of Circuit Packs: %v, must be 1..9",
1956 omci.NumberOfCircuitPacks))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001957 }
1958 omci.CircuitPacks = make([]uint16, omci.NumberOfCircuitPacks)
1959 for index := 0; index < int(omci.NumberOfCircuitPacks); index++ {
1960 omci.CircuitPacks[index] = binary.BigEndian.Uint16(data[10+(index*2):])
1961 }
1962 return nil
1963}
1964
1965func decodeStartSoftwareDownloadRequest(data []byte, p gopacket.PacketBuilder) error {
1966 omci := &StartSoftwareDownloadRequest{}
1967 omci.MsgLayerType = LayerTypeStartSoftwareDownloadRequest
1968 return decodingLayerDecoder(omci, data, p)
1969}
1970
Matteo Scandolof9d43412021-01-12 11:11:34 -08001971// SerializeTo provides serialization of an Start Software Download Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001972func (omci *StartSoftwareDownloadRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
1973 // Basic (common) OMCI Header is 8 octets, 10
1974 err := omci.MeBasePacket.SerializeTo(b)
1975 if err != nil {
1976 return err
1977 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08001978 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001979 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08001980 if omciErr.StatusCode() != me.Success {
1981 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001982 }
1983 // ME needs to support Start Software Download
1984 if !me.SupportsMsgType(entity, me.StartSoftwareDownload) {
1985 return me.NewProcessingError("managed entity does not support the SStart Software Download Message-Type")
1986 }
1987 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08001988 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001989 return me.NewProcessingError("invalid Entity Class for Start Software Download request")
1990 }
1991 if omci.NumberOfCircuitPacks < 1 || omci.NumberOfCircuitPacks > 9 {
Matteo Scandolof9d43412021-01-12 11:11:34 -08001992 return me.NewProcessingError(fmt.Sprintf("invalid number of Circuit Packs: %v, must be 1..9",
1993 omci.NumberOfCircuitPacks))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001994 }
1995 bytes, err := b.AppendBytes(6 + (2 * int(omci.NumberOfCircuitPacks)))
1996 if err != nil {
1997 return err
1998 }
1999 bytes[0] = omci.WindowSize
2000 binary.BigEndian.PutUint32(bytes[1:], omci.ImageSize)
2001 bytes[5] = omci.NumberOfCircuitPacks
2002 for index := 0; index < int(omci.NumberOfCircuitPacks); index++ {
2003 binary.BigEndian.PutUint16(bytes[6+(index*2):], omci.CircuitPacks[index])
2004 }
2005 return nil
2006}
2007
2008/////////////////////////////////////////////////////////////////////////////
2009//
2010type downloadResults struct {
2011 ManagedEntityID uint16 // ME ID of software image entity instance (slot number plus instance 0..1 or 2..254 vendor-specific)
2012 Result me.Results
2013}
2014
2015func (dr *downloadResults) String() string {
2016 return fmt.Sprintf("ME: %v (%#x), Results: %d (%v)", dr.ManagedEntityID, dr.ManagedEntityID,
2017 dr.Result, dr.Result)
2018}
2019
2020type StartSoftwareDownloadResponse struct {
2021 MeBasePacket // Note: EntityInstance for software download is two specific values
2022 Result me.Results
2023 WindowSize byte // Window Size -1
2024 NumberOfInstances byte
2025 MeResults []downloadResults
2026}
2027
2028func (omci *StartSoftwareDownloadResponse) String() string {
2029 return fmt.Sprintf("%v, Results: %v, Window Size: %v, # of Instances: %v, ME Results: %v",
2030 omci.MeBasePacket.String(), omci.Result, omci.WindowSize, omci.NumberOfInstances, omci.MeResults)
2031}
2032
Matteo Scandolof9d43412021-01-12 11:11:34 -08002033// DecodeFromBytes decodes the given bytes of a Start Software Download Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002034func (omci *StartSoftwareDownloadResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2035 // Common ClassID/EntityID decode in msgBase
2036 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2037 if err != nil {
2038 return err
2039 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002040 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002041 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002042 if omciErr.StatusCode() != me.Success {
2043 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002044 }
2045 // ME needs to support Start Software Download
2046 if !me.SupportsMsgType(meDefinition, me.StartSoftwareDownload) {
2047 return me.NewProcessingError("managed entity does not support Start Software Download Message-Type")
2048 }
2049 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002050 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002051 return me.NewProcessingError("invalid Entity Class for Start Software Download response")
2052 }
2053 omci.Result = me.Results(data[4])
2054 if omci.Result > me.DeviceBusy {
2055 msg := fmt.Sprintf("invalid results for Start Software Download response: %v, must be 0..6",
2056 omci.Result)
2057 return errors.New(msg)
2058 }
2059 omci.WindowSize = data[5]
2060 omci.NumberOfInstances = data[6]
2061
2062 if omci.NumberOfInstances > 9 {
2063 msg := fmt.Sprintf("invalid number of Circuit Packs: %v, must be 0..9",
2064 omci.NumberOfInstances)
2065 return errors.New(msg)
2066 }
2067 if omci.NumberOfInstances > 0 {
2068 omci.MeResults = make([]downloadResults, omci.NumberOfInstances)
2069
2070 for index := 0; index < int(omci.NumberOfInstances); index++ {
2071 omci.MeResults[index].ManagedEntityID = binary.BigEndian.Uint16(data[7+(index*3):])
2072 omci.MeResults[index].Result = me.Results(data[9+(index*3)])
2073 if omci.MeResults[index].Result > me.DeviceBusy {
2074 msg := fmt.Sprintf("invalid results for Start Software Download instance %v response: %v, must be 0..6",
2075 index, omci.MeResults[index])
2076 return errors.New(msg)
2077 }
2078 }
2079 }
2080 return nil
2081}
2082
2083func decodeStartSoftwareDownloadResponse(data []byte, p gopacket.PacketBuilder) error {
2084 omci := &StartSoftwareDownloadResponse{}
2085 omci.MsgLayerType = LayerTypeStartSoftwareDownloadResponse
2086 return decodingLayerDecoder(omci, data, p)
2087}
2088
Matteo Scandolof9d43412021-01-12 11:11:34 -08002089// SerializeTo provides serialization of an Start Software Download Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002090func (omci *StartSoftwareDownloadResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2091 // Basic (common) OMCI Header is 8 octets, 10
2092 err := omci.MeBasePacket.SerializeTo(b)
2093 if err != nil {
2094 return err
2095 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002096 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002097 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002098 if omciErr.StatusCode() != me.Success {
2099 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002100 }
2101 // ME needs to support Start Software Download
2102 if !me.SupportsMsgType(meDefinition, me.StartSoftwareDownload) {
2103 return me.NewProcessingError("managed entity does not support Start Software Download Message-Type")
2104 }
2105 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002106 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002107 return me.NewProcessingError("invalid Entity Class for Start Software Download response")
2108 }
2109 bytes, err := b.AppendBytes(3 + (3 * int(omci.NumberOfInstances)))
2110 if err != nil {
2111 return err
2112 }
2113 if omci.Result > me.DeviceBusy {
2114 msg := fmt.Sprintf("invalid results for Start Software Download response: %v, must be 0..6",
2115 omci.Result)
2116 return errors.New(msg)
2117 }
2118 bytes[0] = byte(omci.Result)
2119 bytes[1] = omci.WindowSize
2120 bytes[2] = omci.NumberOfInstances
2121
2122 if omci.NumberOfInstances > 9 {
2123 msg := fmt.Sprintf("invalid number of Circuit Packs: %v, must be 0..9",
2124 omci.NumberOfInstances)
2125 return errors.New(msg)
2126 }
2127 if omci.NumberOfInstances > 0 {
2128 for index := 0; index < int(omci.NumberOfInstances); index++ {
2129 binary.BigEndian.PutUint16(bytes[3+(3*index):], omci.MeResults[index].ManagedEntityID)
2130
2131 if omci.MeResults[index].Result > me.DeviceBusy {
2132 msg := fmt.Sprintf("invalid results for Start Software Download instance %v response: %v, must be 0..6",
2133 index, omci.MeResults[index])
2134 return errors.New(msg)
2135 }
2136 bytes[5+(3*index)] = byte(omci.MeResults[index].Result)
2137 }
2138 }
2139 return nil
2140}
2141
2142/////////////////////////////////////////////////////////////////////////////
2143//
2144type DownloadSectionRequest struct {
2145 MeBasePacket // Note: EntityInstance for software download is two specific values
2146 SectionNumber byte
Girish Gowdrae2683102021-03-05 08:24:26 -08002147 SectionData [31]byte // 0 padding if final transfer requires only a partial block
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002148}
2149
2150func (omci *DownloadSectionRequest) String() string {
2151 return fmt.Sprintf("%v, Section #: %v",
2152 omci.MeBasePacket.String(), omci.SectionNumber)
2153}
2154
Matteo Scandolof9d43412021-01-12 11:11:34 -08002155// DecodeFromBytes decodes the given bytes of a Download Section Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002156func (omci *DownloadSectionRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2157 // Common ClassID/EntityID decode in msgBase
2158 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2159 if err != nil {
2160 return err
2161 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002162 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002163 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002164 if omciErr.StatusCode() != me.Success {
2165 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002166 }
2167 // ME needs to support Download section
2168 if !me.SupportsMsgType(meDefinition, me.DownloadSection) {
2169 return me.NewProcessingError("managed entity does not support Download Section Message-Type")
2170 }
2171 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002172 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002173 return me.NewProcessingError("invalid Entity Class for Download Section request")
2174 }
2175 omci.SectionNumber = data[4]
2176 copy(omci.SectionData[0:], data[5:])
2177 return nil
2178}
2179
2180func decodeDownloadSectionRequest(data []byte, p gopacket.PacketBuilder) error {
2181 omci := &DownloadSectionRequest{}
2182 omci.MsgLayerType = LayerTypeDownloadSectionRequest
2183 return decodingLayerDecoder(omci, data, p)
2184}
2185
Matteo Scandolof9d43412021-01-12 11:11:34 -08002186// SerializeTo provides serialization of an Download Section Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002187func (omci *DownloadSectionRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2188 // Basic (common) OMCI Header is 8 octets, 10
2189 err := omci.MeBasePacket.SerializeTo(b)
2190 if err != nil {
2191 return err
2192 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002193 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002194 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002195 if omciErr.StatusCode() != me.Success {
2196 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002197 }
2198 // ME needs to support Download section
2199 if !me.SupportsMsgType(meDefinition, me.DownloadSection) {
2200 return me.NewProcessingError("managed entity does not support Download Section Message-Type")
2201 }
2202 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002203 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002204 return me.NewProcessingError("invalid Entity Class for Download Section response")
2205 }
Girish Gowdrae2683102021-03-05 08:24:26 -08002206 bytes, err := b.AppendBytes(1 + len(omci.SectionData))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002207 if err != nil {
2208 return err
2209 }
2210 bytes[0] = omci.SectionNumber
2211 copy(bytes[1:], omci.SectionData[0:])
2212 return nil
2213}
2214
2215/////////////////////////////////////////////////////////////////////////////
2216//
2217type DownloadSectionResponse struct {
2218 MeBasePacket // Note: EntityInstance for software download is two specific values
2219 Result me.Results
2220 SectionNumber byte
2221}
2222
2223func (omci *DownloadSectionResponse) String() string {
2224 return fmt.Sprintf("%v, Result: %d (%v), Section #: %v",
2225 omci.MeBasePacket.String(), omci.Result, omci.Result, omci.SectionNumber)
2226}
2227
Matteo Scandolof9d43412021-01-12 11:11:34 -08002228// DecodeFromBytes decodes the given bytes of a Download Section Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002229func (omci *DownloadSectionResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2230 // Common ClassID/EntityID decode in msgBase
2231 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2232 if err != nil {
2233 return err
2234 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002235 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002236 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002237 if omciErr.StatusCode() != me.Success {
2238 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002239 }
2240 // ME needs to support Download section
2241 if !me.SupportsMsgType(meDefinition, me.DownloadSection) {
2242 return me.NewProcessingError("managed entity does not support Download Section Message-Type")
2243 }
2244 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002245 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002246 return me.NewProcessingError("invalid Entity Class for Download Section response")
2247 }
2248 omci.Result = me.Results(data[4])
2249 if omci.Result > me.DeviceBusy {
2250 msg := fmt.Sprintf("invalid results for Download Section response: %v, must be 0..6",
2251 omci.Result)
2252 return errors.New(msg)
2253 }
2254 omci.SectionNumber = data[5]
2255 return nil
2256}
2257
2258func decodeDownloadSectionResponse(data []byte, p gopacket.PacketBuilder) error {
2259 omci := &DownloadSectionResponse{}
2260 omci.MsgLayerType = LayerTypeDownloadSectionResponse
2261 return decodingLayerDecoder(omci, data, p)
2262}
2263
Matteo Scandolof9d43412021-01-12 11:11:34 -08002264// SerializeTo provides serialization of an Download Section Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002265func (omci *DownloadSectionResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2266 // Basic (common) OMCI Header is 8 octets, 10
2267 err := omci.MeBasePacket.SerializeTo(b)
2268 if err != nil {
2269 return err
2270 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002271 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002272 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002273 if omciErr.StatusCode() != me.Success {
2274 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002275 }
2276 // ME needs to support Download section
2277 if !me.SupportsMsgType(meDefinition, me.DownloadSection) {
2278 return me.NewProcessingError("managed entity does not support Download Section Message-Type")
2279 }
2280 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002281 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002282 return me.NewProcessingError("invalid Entity Class for Download Section response")
2283 }
2284 bytes, err := b.AppendBytes(2)
2285 if err != nil {
2286 return err
2287 }
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002288 if omci.Result > me.DeviceBusy {
2289 msg := fmt.Sprintf("invalid results for Download Section response: %v, must be 0..6",
2290 omci.Result)
2291 return errors.New(msg)
2292 }
Girish Gowdrae2683102021-03-05 08:24:26 -08002293 bytes[0] = byte(omci.Result)
2294 bytes[1] = omci.SectionNumber
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002295 return nil
2296}
2297
2298/////////////////////////////////////////////////////////////////////////////
2299//
2300type EndSoftwareDownloadRequest struct {
2301 MeBasePacket // Note: EntityInstance for software download is two specific values
2302 CRC32 uint32
2303 ImageSize uint32
2304 NumberOfInstances byte
2305 ImageInstances []uint16
2306}
2307
2308func (omci *EndSoftwareDownloadRequest) String() string {
2309 return fmt.Sprintf("%v, CRC: %#x, Image Size: %v, Number of Instances: %v, Instances: %v",
2310 omci.MeBasePacket.String(), omci.CRC32, omci.ImageSize, omci.NumberOfInstances, omci.ImageInstances)
2311}
2312
Matteo Scandolof9d43412021-01-12 11:11:34 -08002313// DecodeFromBytes decodes the given bytes of an End Software Download Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002314func (omci *EndSoftwareDownloadRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2315 // Common ClassID/EntityID decode in msgBase
2316 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2317 if err != nil {
2318 return err
2319 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002320 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002321 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002322 if omciErr.StatusCode() != me.Success {
2323 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002324 }
2325 // ME needs to support End Software Download
2326 if !me.SupportsMsgType(meDefinition, me.EndSoftwareDownload) {
2327 return me.NewProcessingError("managed entity does not support End Software Download Message-Type")
2328 }
2329 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002330 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002331 return me.NewProcessingError("invalid Entity Class for End Software Download request")
2332 }
2333 omci.CRC32 = binary.BigEndian.Uint32(data[4:8])
2334 omci.ImageSize = binary.BigEndian.Uint32(data[8:12])
Girish Gowdrae2683102021-03-05 08:24:26 -08002335 omci.NumberOfInstances = data[12]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002336
2337 if omci.NumberOfInstances < 1 || omci.NumberOfInstances > 9 {
Matteo Scandolof9d43412021-01-12 11:11:34 -08002338 return me.NewProcessingError(fmt.Sprintf("invalid number of Instances: %v, must be 1..9",
2339 omci.NumberOfInstances))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002340 }
2341 omci.ImageInstances = make([]uint16, omci.NumberOfInstances)
2342
2343 for index := 0; index < int(omci.NumberOfInstances); index++ {
Girish Gowdrae2683102021-03-05 08:24:26 -08002344 omci.ImageInstances[index] = binary.BigEndian.Uint16(data[13+(index*2):])
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002345 }
2346 return nil
2347}
2348
2349func decodeEndSoftwareDownloadRequest(data []byte, p gopacket.PacketBuilder) error {
2350 omci := &EndSoftwareDownloadRequest{}
2351 omci.MsgLayerType = LayerTypeEndSoftwareDownloadRequest
2352 return decodingLayerDecoder(omci, data, p)
2353}
2354
Matteo Scandolof9d43412021-01-12 11:11:34 -08002355// SerializeTo provides serialization of an End Software Download Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002356func (omci *EndSoftwareDownloadRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2357 // Basic (common) OMCI Header is 8 octets, 10
2358 err := omci.MeBasePacket.SerializeTo(b)
2359 if err != nil {
2360 return err
2361 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002362 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002363 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002364 if omciErr.StatusCode() != me.Success {
2365 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002366 }
2367 // ME needs to support End Software Download
2368 if !me.SupportsMsgType(meDefinition, me.EndSoftwareDownload) {
2369 return me.NewProcessingError("managed entity does not support Start End Download Message-Type")
2370 }
2371 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002372 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002373 return me.NewProcessingError("invalid Entity Class for End Software Download response")
2374 }
2375 if omci.NumberOfInstances < 1 || omci.NumberOfInstances > 9 {
Matteo Scandolof9d43412021-01-12 11:11:34 -08002376 return me.NewProcessingError(fmt.Sprintf("invalid number of Instances: %v, must be 1..9",
2377 omci.NumberOfInstances))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002378 }
2379 bytes, err := b.AppendBytes(9 + (2 * int(omci.NumberOfInstances)))
2380 if err != nil {
2381 return err
2382 }
Girish Gowdrae2683102021-03-05 08:24:26 -08002383 binary.BigEndian.PutUint32(bytes[0:4], omci.CRC32)
2384 binary.BigEndian.PutUint32(bytes[4:8], omci.ImageSize)
2385 bytes[8] = omci.NumberOfInstances
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002386 for index := 0; index < int(omci.NumberOfInstances); index++ {
Girish Gowdrae2683102021-03-05 08:24:26 -08002387 binary.BigEndian.PutUint16(bytes[9+(index*2):], omci.ImageInstances[index])
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002388 }
2389 return nil
2390}
2391
2392/////////////////////////////////////////////////////////////////////////////
2393//
2394type EndSoftwareDownloadResponse struct {
2395 MeBasePacket // Note: EntityInstance for software download is two specific values
2396 Result me.Results
2397 NumberOfInstances byte
2398 MeResults []downloadResults
2399}
2400
2401func (omci *EndSoftwareDownloadResponse) String() string {
2402 return fmt.Sprintf("%v, Result: %d (%v), Number of Instances: %v, ME Results: %v",
2403 omci.MeBasePacket.String(), omci.Result, omci.Result, omci.NumberOfInstances, omci.MeResults)
2404}
2405
Matteo Scandolof9d43412021-01-12 11:11:34 -08002406// DecodeFromBytes decodes the given bytes of an End Software Download Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002407func (omci *EndSoftwareDownloadResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2408 // Common ClassID/EntityID decode in msgBase
2409 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2410 if err != nil {
2411 return err
2412 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002413 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002414 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002415 if omciErr.StatusCode() != me.Success {
2416 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002417 }
2418 // ME needs to support End Software Download
2419 if !me.SupportsMsgType(meDefinition, me.EndSoftwareDownload) {
2420 return me.NewProcessingError("managed entity does not support End Software Download Message-Type")
2421 }
2422 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002423 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002424 return me.NewProcessingError("invalid Entity Class for End Software Download response")
2425 }
2426 omci.Result = me.Results(data[4])
2427 if omci.Result > me.DeviceBusy {
2428 msg := fmt.Sprintf("invalid results for End Software Download response: %v, must be 0..6",
2429 omci.Result)
2430 return errors.New(msg)
2431 }
2432 omci.NumberOfInstances = data[5]
2433
2434 if omci.NumberOfInstances > 9 {
2435 msg := fmt.Sprintf("invalid number of Instances: %v, must be 0..9",
2436 omci.NumberOfInstances)
2437 return errors.New(msg)
2438 }
2439 if omci.NumberOfInstances > 0 {
2440 omci.MeResults = make([]downloadResults, omci.NumberOfInstances)
2441
2442 for index := 0; index < int(omci.NumberOfInstances); index++ {
2443 omci.MeResults[index].ManagedEntityID = binary.BigEndian.Uint16(data[6+(index*3):])
2444 omci.MeResults[index].Result = me.Results(data[8+(index*3)])
2445 if omci.MeResults[index].Result > me.DeviceBusy {
2446 msg := fmt.Sprintf("invalid results for End Software Download instance %v response: %v, must be 0..6",
2447 index, omci.MeResults[index])
2448 return errors.New(msg)
2449 }
2450 }
2451 }
2452 return nil
2453}
2454
2455func decodeEndSoftwareDownloadResponse(data []byte, p gopacket.PacketBuilder) error {
2456 omci := &EndSoftwareDownloadResponse{}
2457 omci.MsgLayerType = LayerTypeEndSoftwareDownloadResponse
2458 return decodingLayerDecoder(omci, data, p)
2459}
2460
Matteo Scandolof9d43412021-01-12 11:11:34 -08002461// SerializeTo provides serialization of an End Software Download Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002462func (omci *EndSoftwareDownloadResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2463 // Basic (common) OMCI Header is 8 octets, 10
2464 err := omci.MeBasePacket.SerializeTo(b)
2465 if err != nil {
2466 return err
2467 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002468 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002469 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002470 if omciErr.StatusCode() != me.Success {
2471 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002472 }
2473 // ME needs to support End Software Download
2474 if !me.SupportsMsgType(meDefinition, me.EndSoftwareDownload) {
2475 return me.NewProcessingError("managed entity does not support End End Download Message-Type")
2476 }
2477 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002478 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002479 return me.NewProcessingError("invalid Entity Class for End Download response")
2480 }
Girish Gowdrae2683102021-03-05 08:24:26 -08002481 bytes, err := b.AppendBytes(2 + (3 * int(omci.NumberOfInstances)))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002482 if err != nil {
2483 return err
2484 }
2485 if omci.Result > me.DeviceBusy {
2486 msg := fmt.Sprintf("invalid results for End Software Download response: %v, must be 0..6",
2487 omci.Result)
2488 return errors.New(msg)
2489 }
2490 bytes[0] = byte(omci.Result)
2491 bytes[1] = omci.NumberOfInstances
2492
2493 if omci.NumberOfInstances > 9 {
2494 msg := fmt.Sprintf("invalid number of Instances: %v, must be 0..9",
2495 omci.NumberOfInstances)
2496 return errors.New(msg)
2497 }
2498 if omci.NumberOfInstances > 0 {
2499 for index := 0; index < int(omci.NumberOfInstances); index++ {
2500 binary.BigEndian.PutUint16(bytes[2+(3*index):], omci.MeResults[index].ManagedEntityID)
2501
2502 if omci.MeResults[index].Result > me.DeviceBusy {
2503 msg := fmt.Sprintf("invalid results for End Software Download instance %v response: %v, must be 0..6",
2504 index, omci.MeResults[index])
2505 return errors.New(msg)
2506 }
2507 bytes[4+(3*index)] = byte(omci.MeResults[index].Result)
2508 }
2509 }
2510 return nil
2511}
2512
2513/////////////////////////////////////////////////////////////////////////////
2514//
2515type ActivateSoftwareRequest struct {
2516 MeBasePacket // Note: EntityInstance for software download is two specific values
2517 ActivateFlags byte
2518}
2519
2520func (omci *ActivateSoftwareRequest) String() string {
2521 return fmt.Sprintf("%v, Flags: %#x",
2522 omci.MeBasePacket.String(), omci.ActivateFlags)
2523}
2524
Matteo Scandolof9d43412021-01-12 11:11:34 -08002525// DecodeFromBytes decodes the given bytes of an Activate Software Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002526func (omci *ActivateSoftwareRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2527 // Common ClassID/EntityID decode in msgBase
2528 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2529 if err != nil {
2530 return err
2531 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002532 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002533 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002534 if omciErr.StatusCode() != me.Success {
2535 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002536 }
2537 // ME needs to support End Software Download
2538 if !me.SupportsMsgType(meDefinition, me.ActivateSoftware) {
2539 return me.NewProcessingError("managed entity does not support Activate Software Message-Type")
2540 }
2541 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002542 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002543 return me.NewProcessingError("invalid Entity Class for Activate Software request")
2544 }
2545 omci.ActivateFlags = data[4]
2546 if omci.ActivateFlags > 2 {
Matteo Scandolof9d43412021-01-12 11:11:34 -08002547 return me.NewProcessingError(fmt.Sprintf("invalid number of Activation flangs: %v, must be 0..2",
2548 omci.ActivateFlags))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002549 }
2550 return nil
2551}
2552
2553func decodeActivateSoftwareRequest(data []byte, p gopacket.PacketBuilder) error {
2554 omci := &ActivateSoftwareRequest{}
2555 omci.MsgLayerType = LayerTypeActivateSoftwareRequest
2556 return decodingLayerDecoder(omci, data, p)
2557}
2558
Matteo Scandolof9d43412021-01-12 11:11:34 -08002559// SerializeTo provides serialization of an Activate Software message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002560func (omci *ActivateSoftwareRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2561 // Basic (common) OMCI Header is 8 octets, 10
2562 err := omci.MeBasePacket.SerializeTo(b)
2563 if err != nil {
2564 return err
2565 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002566 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002567 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002568 if omciErr.StatusCode() != me.Success {
2569 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002570 }
2571 // ME needs to support End Software Download
2572 if !me.SupportsMsgType(meDefinition, me.ActivateSoftware) {
2573 return me.NewProcessingError("managed entity does not support Activate Message-Type")
2574 }
2575 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002576 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002577 return me.NewProcessingError("invalid Entity Class for Activate Software request")
2578 }
2579 bytes, err := b.AppendBytes(1)
2580 if err != nil {
2581 return err
2582 }
2583 bytes[0] = omci.ActivateFlags
2584 if omci.ActivateFlags > 2 {
2585 msg := fmt.Sprintf("invalid results for Activate Software request: %v, must be 0..2",
2586 omci.ActivateFlags)
2587 return errors.New(msg)
2588 }
2589 return nil
2590}
2591
2592/////////////////////////////////////////////////////////////////////////////
2593//
2594type ActivateSoftwareResponse struct {
2595 MeBasePacket
2596 Result me.Results
2597}
2598
2599func (omci *ActivateSoftwareResponse) String() string {
2600 return fmt.Sprintf("%v, Result: %d (%v)",
2601 omci.MeBasePacket.String(), omci.Result, omci.Result)
2602}
2603
Matteo Scandolof9d43412021-01-12 11:11:34 -08002604// DecodeFromBytes decodes the given bytes of an Activate Softwre Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002605func (omci *ActivateSoftwareResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2606 // Common ClassID/EntityID decode in msgBase
2607 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2608 if err != nil {
2609 return err
2610 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002611 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002612 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002613 if omciErr.StatusCode() != me.Success {
2614 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002615 }
2616 // ME needs to support End Software Download
2617 if !me.SupportsMsgType(meDefinition, me.ActivateSoftware) {
2618 return me.NewProcessingError("managed entity does not support Activate Software Message-Type")
2619 }
2620 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002621 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002622 return me.NewProcessingError("invalid Entity Class for Activate Software response")
2623 }
2624 omci.Result = me.Results(data[4])
2625 if omci.Result > me.Results(6) {
2626 msg := fmt.Sprintf("invalid results for Activate Software response: %v, must be 0..6",
2627 omci.Result)
2628 return errors.New(msg)
2629 }
2630 return nil
2631}
2632
2633func decodeActivateSoftwareResponse(data []byte, p gopacket.PacketBuilder) error {
2634 omci := &ActivateSoftwareResponse{}
2635 omci.MsgLayerType = LayerTypeActivateSoftwareResponse
2636 return decodingLayerDecoder(omci, data, p)
2637}
2638
Matteo Scandolof9d43412021-01-12 11:11:34 -08002639// SerializeTo provides serialization of an Activate Software Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002640func (omci *ActivateSoftwareResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2641 // Basic (common) OMCI Header is 8 octets, 10
2642 err := omci.MeBasePacket.SerializeTo(b)
2643 if err != nil {
2644 return err
2645 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002646 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002647 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002648 if omciErr.StatusCode() != me.Success {
2649 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002650 }
2651 // ME needs to support End Software Download
2652 if !me.SupportsMsgType(meDefinition, me.ActivateSoftware) {
2653 return me.NewProcessingError("managed entity does not support Activate Message-Type")
2654 }
2655 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002656 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002657 return me.NewProcessingError("invalid Entity Class for Activate Software response")
2658 }
2659 bytes, err := b.AppendBytes(1)
2660 if err != nil {
2661 return err
2662 }
2663 bytes[0] = byte(omci.Result)
2664 if omci.Result > me.Results(6) {
2665 msg := fmt.Sprintf("invalid results for Activate Software response: %v, must be 0..6",
2666 omci.Result)
2667 return errors.New(msg)
2668 }
2669 return nil
2670}
2671
2672/////////////////////////////////////////////////////////////////////////////
2673//
2674type CommitSoftwareRequest struct {
2675 MeBasePacket
2676}
2677
2678func (omci *CommitSoftwareRequest) String() string {
2679 return fmt.Sprintf("%v", omci.MeBasePacket.String())
2680}
2681
Matteo Scandolof9d43412021-01-12 11:11:34 -08002682// DecodeFromBytes decodes the given bytes of a Commit Software Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002683func (omci *CommitSoftwareRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2684 // Common ClassID/EntityID decode in msgBase
2685 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2686 if err != nil {
2687 return err
2688 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002689 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002690 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002691 if omciErr.StatusCode() != me.Success {
2692 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002693 }
2694 // ME needs to support End Software Download
2695 if !me.SupportsMsgType(meDefinition, me.CommitSoftware) {
2696 return me.NewProcessingError("managed entity does not support Commit Software Message-Type")
2697 }
2698 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002699 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002700 return me.NewProcessingError("invalid Entity Class for Commit Software request")
2701 }
2702 return nil
2703}
2704
2705func decodeCommitSoftwareRequest(data []byte, p gopacket.PacketBuilder) error {
2706 omci := &CommitSoftwareRequest{}
2707 omci.MsgLayerType = LayerTypeCommitSoftwareRequest
2708 return decodingLayerDecoder(omci, data, p)
2709}
2710
Matteo Scandolof9d43412021-01-12 11:11:34 -08002711// SerializeTo provides serialization of an Commit Software Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002712func (omci *CommitSoftwareRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2713 // Basic (common) OMCI Header is 8 octets, 10
2714 err := omci.MeBasePacket.SerializeTo(b)
2715 if err != nil {
2716 return err
2717 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002718 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002719 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002720 if omciErr.StatusCode() != me.Success {
2721 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002722 }
2723 // ME needs to support End Software Download
2724 if !me.SupportsMsgType(meDefinition, me.CommitSoftware) {
2725 return me.NewProcessingError("managed entity does not support Commit Message-Type")
2726 }
2727 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002728 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002729 return me.NewProcessingError("invalid Entity Class for Commit Software request")
2730 }
2731 return nil
2732}
2733
2734/////////////////////////////////////////////////////////////////////////////
2735//
2736type CommitSoftwareResponse struct {
2737 MeBasePacket
2738}
2739
2740func (omci *CommitSoftwareResponse) String() string {
2741 return fmt.Sprintf("%v", omci.MeBasePacket.String())
2742}
2743
Matteo Scandolof9d43412021-01-12 11:11:34 -08002744// DecodeFromBytes decodes the given bytes of a Commit Softwar Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002745func (omci *CommitSoftwareResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2746 // Common ClassID/EntityID decode in msgBase
2747 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2748 if err != nil {
2749 return err
2750 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002751 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002752 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002753 if omciErr.StatusCode() != me.Success {
2754 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002755 }
2756 // ME needs to support End Software Download
2757 if !me.SupportsMsgType(meDefinition, me.CommitSoftware) {
2758 return me.NewProcessingError("managed entity does not support Commit Software Message-Type")
2759 }
2760 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002761 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002762 return me.NewProcessingError("invalid Entity Class for Commit Software response")
2763 }
2764 return nil
2765}
2766
2767func decodeCommitSoftwareResponse(data []byte, p gopacket.PacketBuilder) error {
2768 omci := &CommitSoftwareResponse{}
2769 omci.MsgLayerType = LayerTypeCommitSoftwareResponse
2770 return decodingLayerDecoder(omci, data, p)
2771}
2772
Matteo Scandolof9d43412021-01-12 11:11:34 -08002773// SerializeTo provides serialization of an Commit Software Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002774func (omci *CommitSoftwareResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2775 // Basic (common) OMCI Header is 8 octets, 10
2776 err := omci.MeBasePacket.SerializeTo(b)
2777 if err != nil {
2778 return err
2779 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002780 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002781 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002782 if omciErr.StatusCode() != me.Success {
2783 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002784 }
2785 // ME needs to support End Software Download
2786 if !me.SupportsMsgType(meDefinition, me.CommitSoftware) {
2787 return me.NewProcessingError("managed entity does not support Commit Message-Type")
2788 }
2789 // Software Image Entity Class are always use the Software Image
Matteo Scandolof9d43412021-01-12 11:11:34 -08002790 if omci.EntityClass != me.SoftwareImageClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002791 return me.NewProcessingError("invalid Entity Class for Commit Software response")
2792 }
2793 return nil
2794}
2795
2796/////////////////////////////////////////////////////////////////////////////
2797//
2798type SynchronizeTimeRequest struct {
2799 MeBasePacket
2800 Year uint16
2801 Month uint8
2802 Day uint8
2803 Hour uint8
2804 Minute uint8
2805 Second uint8
2806}
2807
2808func (omci *SynchronizeTimeRequest) String() string {
2809 return fmt.Sprintf("%v, Date-Time: %d/%d/%d-%02d:%02d:%02d",
2810 omci.MeBasePacket.String(), omci.Year, omci.Month, omci.Day, omci.Hour, omci.Minute, omci.Second)
2811}
2812
Matteo Scandolof9d43412021-01-12 11:11:34 -08002813// DecodeFromBytes decodes the given bytes of a Synchronize Time Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002814func (omci *SynchronizeTimeRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2815 // Common ClassID/EntityID decode in msgBase
2816 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2817 if err != nil {
2818 return err
2819 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002820 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002821 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002822 if omciErr.StatusCode() != me.Success {
2823 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002824 }
2825 // ME needs to support Synchronize Time
2826 if !me.SupportsMsgType(meDefinition, me.SynchronizeTime) {
2827 return me.NewProcessingError("managed entity does not support Synchronize Time Message-Type")
2828 }
2829 // Synchronize Time Entity Class are always ONU-G (256) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08002830 if omci.EntityClass != me.OnuGClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002831 return me.NewProcessingError("invalid Entity Class for Synchronize Time request")
2832 }
2833 if omci.EntityInstance != 0 {
2834 return me.NewUnknownInstanceError("invalid Entity Instance for Synchronize Time request")
2835 }
2836 omci.Year = binary.BigEndian.Uint16(data[4:6])
2837 omci.Month = data[6]
2838 omci.Day = data[7]
2839 omci.Hour = data[8]
2840 omci.Minute = data[9]
2841 omci.Second = data[10]
2842 return nil
2843}
2844
2845func decodeSynchronizeTimeRequest(data []byte, p gopacket.PacketBuilder) error {
2846 omci := &SynchronizeTimeRequest{}
2847 omci.MsgLayerType = LayerTypeSynchronizeTimeRequest
2848 return decodingLayerDecoder(omci, data, p)
2849}
2850
Matteo Scandolof9d43412021-01-12 11:11:34 -08002851// SerializeTo provides serialization of an Synchronize Time Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002852func (omci *SynchronizeTimeRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2853 // Basic (common) OMCI Header is 8 octets, 10
2854 err := omci.MeBasePacket.SerializeTo(b)
2855 if err != nil {
2856 return err
2857 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002858 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002859 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002860 if omciErr.StatusCode() != me.Success {
2861 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002862 }
2863 // ME needs to support Synchronize Time
2864 if !me.SupportsMsgType(entity, me.SynchronizeTime) {
2865 return me.NewProcessingError("managed entity does not support the Synchronize Time Message-Type")
2866 }
2867 bytes, err := b.AppendBytes(7)
2868 if err != nil {
2869 return err
2870 }
2871 binary.BigEndian.PutUint16(bytes[0:2], omci.Year)
2872 bytes[2] = omci.Month
2873 bytes[3] = omci.Day
2874 bytes[4] = omci.Hour
2875 bytes[5] = omci.Minute
2876 bytes[6] = omci.Second
2877 return nil
2878}
2879
2880/////////////////////////////////////////////////////////////////////////////
2881//
2882type SynchronizeTimeResponse struct {
2883 MeBasePacket
2884 Result me.Results
2885 SuccessResults uint8 // Only if 'Result' is 0 -> success
2886}
2887
2888func (omci *SynchronizeTimeResponse) String() string {
2889 return fmt.Sprintf("%v, Results: %d (%v), Success: %d",
2890 omci.MeBasePacket.String(), omci.Result, omci.Result, omci.SuccessResults)
2891}
2892
Matteo Scandolof9d43412021-01-12 11:11:34 -08002893// DecodeFromBytes decodes the given bytes of a Synchronize Time Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002894func (omci *SynchronizeTimeResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2895 // Common ClassID/EntityID decode in msgBase
2896 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2897 if err != nil {
2898 return err
2899 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002900 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002901 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002902 if omciErr.StatusCode() != me.Success {
2903 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002904 }
2905 // ME needs to support Synchronize Time
2906 if !me.SupportsMsgType(meDefinition, me.SynchronizeTime) {
2907 return me.NewProcessingError("managed entity does not support Synchronize Time Message-Type")
2908 }
2909 // Synchronize Time Entity Class are always ONU-G (256) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08002910 if omci.EntityClass != me.OnuGClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002911 return me.NewProcessingError("invalid Entity Class for Synchronize Time response")
2912 }
2913 if omci.EntityInstance != 0 {
2914 return me.NewUnknownInstanceError("invalid Entity Instance for Synchronize Time response")
2915 }
2916 omci.Result = me.Results(data[4])
2917 if omci.Result > me.DeviceBusy {
2918 msg := fmt.Sprintf("invalid results code: %v, must be 0..8", omci.Result)
2919 return errors.New(msg)
2920 }
2921 omci.SuccessResults = data[5]
2922 return nil
2923}
2924
2925func decodeSynchronizeTimeResponse(data []byte, p gopacket.PacketBuilder) error {
2926 omci := &SynchronizeTimeResponse{}
2927 omci.MsgLayerType = LayerTypeSynchronizeTimeResponse
2928 return decodingLayerDecoder(omci, data, p)
2929}
2930
Matteo Scandolof9d43412021-01-12 11:11:34 -08002931// SerializeTo provides serialization of an Synchronize Time Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002932func (omci *SynchronizeTimeResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
2933 // Basic (common) OMCI Header is 8 octets, 10
2934 err := omci.MeBasePacket.SerializeTo(b)
2935 if err != nil {
2936 return err
2937 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002938 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002939 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002940 if omciErr.StatusCode() != me.Success {
2941 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002942 }
2943 // Synchronize Time Entity Class are always ONU DATA (2) and Entity Instance of 0
Matteo Scandolof9d43412021-01-12 11:11:34 -08002944 if omci.EntityClass != me.OnuGClassID {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002945 return me.NewProcessingError("invalid Entity Class for Synchronize Time response")
2946 }
2947 if omci.EntityInstance != 0 {
2948 return me.NewUnknownInstanceError("invalid Entity Instance for Synchronize Time response")
2949 }
2950 // ME needs to support Synchronize Time
2951 if !me.SupportsMsgType(entity, me.SynchronizeTime) {
2952 return me.NewProcessingError("managed entity does not support the Synchronize Time Message-Type")
2953 }
2954 numBytes := 2
2955 if omci.Result != me.Success {
2956 numBytes = 1
2957 }
2958 bytes, err := b.AppendBytes(numBytes)
2959 if err != nil {
2960 return err
2961 }
2962 bytes[0] = uint8(omci.Result)
2963 if omci.Result == me.Success {
2964 bytes[1] = omci.SuccessResults
2965 }
2966 return nil
2967}
2968
2969/////////////////////////////////////////////////////////////////////////////
2970//
2971type RebootRequest struct {
2972 MeBasePacket
2973 RebootCondition byte
2974}
2975
2976func (omci *RebootRequest) String() string {
2977 return fmt.Sprintf("%v, Reboot Condition: %v",
2978 omci.MeBasePacket.String(), omci.RebootCondition)
2979}
2980
Matteo Scandolof9d43412021-01-12 11:11:34 -08002981// DecodeFromBytes decodes the given bytes of a Reboot Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002982func (omci *RebootRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
2983 // Common ClassID/EntityID decode in msgBase
2984 err := omci.MeBasePacket.DecodeFromBytes(data, p)
2985 if err != nil {
2986 return err
2987 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08002988 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002989 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08002990 if omciErr.StatusCode() != me.Success {
2991 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07002992 }
2993 // ME needs to support Reboot
2994 if !me.SupportsMsgType(meDefinition, me.Reboot) {
2995 return me.NewProcessingError("managed entity does not support Reboot Message-Type")
2996 }
2997 omci.RebootCondition = data[4]
2998 if omci.RebootCondition > 3 {
2999 msg := fmt.Sprintf("invalid reboot condition code: %v, must be 0..3", omci.RebootCondition)
3000 return errors.New(msg)
3001 }
3002 return nil
3003}
3004
3005func decodeRebootRequest(data []byte, p gopacket.PacketBuilder) error {
3006 omci := &RebootRequest{}
3007 omci.MsgLayerType = LayerTypeRebootRequest
3008 return decodingLayerDecoder(omci, data, p)
3009}
3010
Matteo Scandolof9d43412021-01-12 11:11:34 -08003011// SerializeTo provides serialization of an Reboot Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003012func (omci *RebootRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3013 // Basic (common) OMCI Header is 8 octets, 10
3014 err := omci.MeBasePacket.SerializeTo(b)
3015 if err != nil {
3016 return err
3017 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003018 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003019 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003020 if omciErr.StatusCode() != me.Success {
3021 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003022 }
3023 // ME needs to support Reboot
3024 if !me.SupportsMsgType(entity, me.Reboot) {
3025 return me.NewProcessingError("managed entity does not support the Synchronize Time Message-Type")
3026 }
3027 bytes, err := b.AppendBytes(1)
3028 if err != nil {
3029 return err
3030 }
3031 if omci.RebootCondition > 3 {
Matteo Scandolof9d43412021-01-12 11:11:34 -08003032 return me.NewProcessingError(fmt.Sprintf("invalid reboot condition code: %v, must be 0..3",
3033 omci.RebootCondition))
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003034 }
3035 bytes[0] = omci.RebootCondition
3036 return nil
3037}
3038
3039/////////////////////////////////////////////////////////////////////////////
3040//
3041type RebootResponse struct {
3042 MeBasePacket
3043 Result me.Results
3044}
3045
Matteo Scandolof9d43412021-01-12 11:11:34 -08003046// DecodeFromBytes decodes the given bytes of a Reboot Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003047func (omci *RebootResponse) String() string {
3048 return fmt.Sprintf("%v, Result: %d (%v)",
3049 omci.MeBasePacket.String(), omci.Result, omci.Result)
3050}
3051
Matteo Scandolof9d43412021-01-12 11:11:34 -08003052// DecodeFromBytes decodes the given bytes of a Reboot Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003053func (omci *RebootResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3054 // Common ClassID/EntityID decode in msgBase
3055 err := omci.MeBasePacket.DecodeFromBytes(data, p)
3056 if err != nil {
3057 return err
3058 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003059 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003060 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003061 if omciErr.StatusCode() != me.Success {
3062 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003063 }
3064 // ME needs to support Reboot
3065 if !me.SupportsMsgType(meDefinition, me.Reboot) {
3066 return me.NewProcessingError("managed entity does not support Reboot Message-Type")
3067 }
3068 if omci.Result > 6 {
3069 msg := fmt.Sprintf("invalid reboot results code: %v, must be 0..6", omci.Result)
3070 return errors.New(msg)
3071 }
3072 omci.Result = me.Results(data[4])
3073 return nil
3074}
3075
3076func decodeRebootResponse(data []byte, p gopacket.PacketBuilder) error {
3077 omci := &RebootResponse{}
3078 omci.MsgLayerType = LayerTypeRebootResponse
3079 return decodingLayerDecoder(omci, data, p)
3080}
3081
Matteo Scandolof9d43412021-01-12 11:11:34 -08003082// SerializeTo provides serialization of an Reboot Response message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003083func (omci *RebootResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3084 // Basic (common) OMCI Header is 8 octets, 10
3085 err := omci.MeBasePacket.SerializeTo(b)
3086 if err != nil {
3087 return err
3088 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003089 entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003090 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003091 if omciErr.StatusCode() != me.Success {
3092 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003093 }
3094 // ME needs to support Reboot
3095 if !me.SupportsMsgType(entity, me.Reboot) {
3096 return me.NewProcessingError("managed entity does not support the Synchronize Time Message-Type")
3097 }
3098 bytes, err := b.AppendBytes(1)
3099 if err != nil {
3100 return err
3101 }
3102 if omci.Result > 6 {
3103 msg := fmt.Sprintf("invalid reboot results code: %v, must be 0..6", omci.Result)
3104 return errors.New(msg)
3105 }
3106 bytes[0] = byte(omci.Result)
3107 return nil
3108}
3109
3110/////////////////////////////////////////////////////////////////////////////
3111//
3112type GetNextRequest struct {
3113 MeBasePacket
3114 AttributeMask uint16
3115 SequenceNumber uint16
3116}
3117
3118func (omci *GetNextRequest) String() string {
3119 return fmt.Sprintf("%v, Attribute Mask: %#x, Sequence Number: %v",
3120 omci.MeBasePacket.String(), omci.AttributeMask, omci.SequenceNumber)
3121}
3122
Matteo Scandolof9d43412021-01-12 11:11:34 -08003123// DecodeFromBytes decodes the given bytes of a Get Next Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003124func (omci *GetNextRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3125 // Common ClassID/EntityID decode in msgBase
3126 err := omci.MeBasePacket.DecodeFromBytes(data, p)
3127 if err != nil {
3128 return err
3129 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003130 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003131 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003132 if omciErr.StatusCode() != me.Success {
3133 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003134 }
3135 // ME needs to support GetNext
3136 if !me.SupportsMsgType(meDefinition, me.GetNext) {
3137 return me.NewProcessingError("managed entity does not support Get Next Message-Type")
3138 }
3139 // Note: G.988 specifies that an error code of (3) should result if more
3140 // than one attribute is requested
3141 // TODO: Return error. Have flag to optionally allow it to be encoded
3142 // TODO: Check that the attribute is a table attirbute. Issue warning or return error
3143 omci.AttributeMask = binary.BigEndian.Uint16(data[4:6])
3144 omci.SequenceNumber = binary.BigEndian.Uint16(data[6:8])
3145 return nil
3146}
3147
3148func decodeGetNextRequest(data []byte, p gopacket.PacketBuilder) error {
3149 omci := &GetNextRequest{}
3150 omci.MsgLayerType = LayerTypeGetNextRequest
3151 return decodingLayerDecoder(omci, data, p)
3152}
3153
Matteo Scandolof9d43412021-01-12 11:11:34 -08003154// SerializeTo provides serialization of an Get Next Message Type Request
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003155func (omci *GetNextRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3156 // Basic (common) OMCI Header is 8 octets, 10
3157 err := omci.MeBasePacket.SerializeTo(b)
3158 if err != nil {
3159 return err
3160 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003161 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003162 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003163 if omciErr.StatusCode() != me.Success {
3164 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003165 }
3166 // ME needs to support GetNext
3167 if !me.SupportsMsgType(meDefinition, me.GetNext) {
3168 return me.NewProcessingError("managed entity does not support Get Next Message-Type")
3169 }
3170 bytes, err := b.AppendBytes(4)
3171 if err != nil {
3172 return err
3173 }
3174 binary.BigEndian.PutUint16(bytes, omci.AttributeMask)
3175 binary.BigEndian.PutUint16(bytes[2:], omci.SequenceNumber)
3176 return nil
3177}
3178
3179/////////////////////////////////////////////////////////////////////////////
3180//
3181type GetNextResponse struct {
3182 MeBasePacket
3183 Result me.Results
3184 AttributeMask uint16
3185 Attributes me.AttributeValueMap
3186}
3187
Matteo Scandolof9d43412021-01-12 11:11:34 -08003188// SerializeTo provides serialization of an Get Next Message Type Response
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003189func (omci *GetNextResponse) String() string {
3190 return fmt.Sprintf("%v, Result: %v, Attribute Mask: %#x, Attributes: %v",
3191 omci.MeBasePacket.String(), omci.Result, omci.AttributeMask, omci.Attributes)
3192}
3193
Matteo Scandolof9d43412021-01-12 11:11:34 -08003194// DecodeFromBytes decodes the given bytes of a Get Next Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003195func (omci *GetNextResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3196 // Common ClassID/EntityID decode in msgBase
3197 err := omci.MeBasePacket.DecodeFromBytes(data, p)
3198 if err != nil {
3199 return err
3200 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003201 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003202 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003203 if omciErr.StatusCode() != me.Success {
3204 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003205 }
3206 // ME needs to support Set
3207 if !me.SupportsMsgType(meDefinition, me.GetNext) {
3208 return me.NewProcessingError("managed entity does not support Get Next Message-Type")
3209 }
3210 omci.Result = me.Results(data[4])
3211 if omci.Result > 6 {
3212 msg := fmt.Sprintf("invalid get next results code: %v, must be 0..6", omci.Result)
3213 return errors.New(msg)
3214 }
3215 omci.AttributeMask = binary.BigEndian.Uint16(data[5:7])
3216
3217 // Attribute decode
3218 omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[7:], p, byte(GetNextResponseType))
3219 if err != nil {
3220 return err
3221 }
3222 // Validate all attributes support read
3223 for attrName := range omci.Attributes {
3224 attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
3225 if err != nil {
3226 return err
3227 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003228 if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Read) {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003229 msg := fmt.Sprintf("attribute '%v' does not support read access", attrName)
3230 return me.NewProcessingError(msg)
3231 }
3232 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003233 if eidDef, eidDefOK := meDefinition.GetAttributeDefinitions()[0]; eidDefOK {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003234 omci.Attributes[eidDef.GetName()] = omci.EntityInstance
3235 return nil
3236 }
3237 panic("All Managed Entities have an EntityID attribute")
3238}
3239
3240func decodeGetNextResponse(data []byte, p gopacket.PacketBuilder) error {
3241 omci := &GetNextResponse{}
3242 omci.MsgLayerType = LayerTypeGetNextResponse
3243 return decodingLayerDecoder(omci, data, p)
3244}
3245
Matteo Scandolof9d43412021-01-12 11:11:34 -08003246// SerializeTo provides serialization of an Get Next Message Type Response
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003247func (omci *GetNextResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3248 // Basic (common) OMCI Header is 8 octets, 10
3249 err := omci.MeBasePacket.SerializeTo(b)
3250 if err != nil {
3251 return err
3252 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003253 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003254 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003255 if omciErr.StatusCode() != me.Success {
3256 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003257 }
3258 // ME needs to support Get
3259 if !me.SupportsMsgType(meDefinition, me.GetNext) {
3260 return me.NewProcessingError("managed entity does not support the Get Next Message-Type")
3261 }
3262 bytes, err := b.AppendBytes(3)
3263 if err != nil {
3264 return err
3265 }
3266 bytes[0] = byte(omci.Result)
3267 if omci.Result > 6 {
3268 msg := fmt.Sprintf("invalid get next results code: %v, must be 0..6", omci.Result)
3269 return errors.New(msg)
3270 }
3271 binary.BigEndian.PutUint16(bytes[1:3], omci.AttributeMask)
3272
3273 // Validate all attributes support read
3274 for attrName := range omci.Attributes {
3275 attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
3276 if err != nil {
3277 return err
3278 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003279 if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Read) {
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003280 msg := fmt.Sprintf("attribute '%v' does not support read access", attrName)
3281 return me.NewProcessingError(msg)
3282 }
3283 }
3284 // Attribute serialization
3285 switch omci.Result {
3286 default:
3287 break
3288
3289 case me.Success:
3290 // TODO: Only Baseline supported at this time
3291 bytesAvailable := MaxBaselineLength - 11 - 8
3292
Matteo Scandolof9d43412021-01-12 11:11:34 -08003293 err, _ = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b,
3294 byte(GetNextResponseType), bytesAvailable, false)
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003295 if err != nil {
3296 return err
3297 }
3298 }
3299 return nil
3300}
3301
3302/////////////////////////////////////////////////////////////////////////////
3303//
3304type TestResultMsg struct {
3305 MeBasePacket
3306}
3307
3308func (omci *TestResultMsg) String() string {
3309 return fmt.Sprintf("%v", omci.MeBasePacket.String())
3310}
3311
Matteo Scandolof9d43412021-01-12 11:11:34 -08003312// DecodeFromBytes decodes the given bytes of a Test Result Notification into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003313func (omci *TestResultMsg) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3314 // Common ClassID/EntityID decode in msgBase
3315 err := omci.MeBasePacket.DecodeFromBytes(data, p)
3316 if err != nil {
3317 return err
3318 }
3319 return errors.New("need to implement") // TODO: Fix me) // return nil
3320}
3321
3322func decodeTestResult(data []byte, p gopacket.PacketBuilder) error {
3323 omci := &TestResultMsg{}
3324 omci.MsgLayerType = LayerTypeTestResult
3325 return decodingLayerDecoder(omci, data, p)
3326}
3327
Matteo Scandolof9d43412021-01-12 11:11:34 -08003328// SerializeTo provides serialization of an Test Result notification message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003329func (omci *TestResultMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3330 // Basic (common) OMCI Header is 8 octets, 10
3331 err := omci.MeBasePacket.SerializeTo(b)
3332 if err != nil {
3333 return err
3334 }
3335 return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b)
3336}
3337
3338/////////////////////////////////////////////////////////////////////////////
3339//
3340type GetCurrentDataRequest struct {
3341 MeBasePacket
3342 AttributeMask uint16
3343}
3344
3345func (omci *GetCurrentDataRequest) String() string {
3346 return fmt.Sprintf("%v, Attribute Mask: %#x",
3347 omci.MeBasePacket.String(), omci.AttributeMask)
3348}
3349
Matteo Scandolof9d43412021-01-12 11:11:34 -08003350// DecodeFromBytes decodes the given bytes of a Get Current Data Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003351func (omci *GetCurrentDataRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3352 // Common ClassID/EntityID decode in msgBase
3353 err := omci.MeBasePacket.DecodeFromBytes(data, p)
3354 if err != nil {
3355 return err
3356 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003357 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003358 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003359 if omciErr.StatusCode() != me.Success {
3360 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003361 }
3362 // ME needs to support GetNext
3363 if !me.SupportsMsgType(meDefinition, me.GetCurrentData) {
3364 return me.NewProcessingError("managed entity does not support Get Current Data Message-Type")
3365 }
3366 // Note: G.988 specifies that an error code of (3) should result if more
3367 // than one attribute is requested
3368 omci.AttributeMask = binary.BigEndian.Uint16(data[4:6])
3369 return nil
3370}
3371
3372func decodeGetCurrentDataRequest(data []byte, p gopacket.PacketBuilder) error {
3373 omci := &GetCurrentDataRequest{}
3374 omci.MsgLayerType = LayerTypeGetCurrentDataRequest
3375 return decodingLayerDecoder(omci, data, p)
3376}
3377
Matteo Scandolof9d43412021-01-12 11:11:34 -08003378// SerializeTo provides serialization of an Get Current Data Request message
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003379func (omci *GetCurrentDataRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3380 // Basic (common) OMCI Header is 8 octets, 10
3381 err := omci.MeBasePacket.SerializeTo(b)
3382 if err != nil {
3383 return err
3384 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003385 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003386 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003387 if omciErr.StatusCode() != me.Success {
3388 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003389 }
3390 // ME needs to support GetNext
3391 if !me.SupportsMsgType(meDefinition, me.GetCurrentData) {
3392 return me.NewProcessingError("managed entity does not support Get Current Data Message-Type")
3393 }
3394 bytes, err := b.AppendBytes(2)
3395 if err != nil {
3396 return err
3397 }
3398 binary.BigEndian.PutUint16(bytes, omci.AttributeMask)
3399 return nil
3400}
3401
3402/////////////////////////////////////////////////////////////////////////////
3403//
3404type GetCurrentDataResponse struct {
3405 MeBasePacket
3406 Result me.Results
3407 AttributeMask uint16
3408 Attributes me.AttributeValueMap
3409}
3410
3411func (omci *GetCurrentDataResponse) String() string {
3412 return fmt.Sprintf("%v, Result: %d (%v), Attribute Mask: %#x, Attributes: %v",
3413 omci.MeBasePacket.String(), omci.Result, omci.Result, omci.AttributeMask, omci.Attributes)
3414}
3415
Matteo Scandolof9d43412021-01-12 11:11:34 -08003416// DecodeFromBytes decodes the given bytes of a Get Current Data Respnse into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003417func (omci *GetCurrentDataResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3418 // Common ClassID/EntityID decode in msgBase
3419 err := omci.MeBasePacket.DecodeFromBytes(data, p)
3420 if err != nil {
3421 return err
3422 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003423 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003424 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003425 if omciErr.StatusCode() != me.Success {
3426 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003427 }
3428 // ME needs to support Set
3429 if !me.SupportsMsgType(meDefinition, me.GetCurrentData) {
3430 return me.NewProcessingError("managed entity does not support Get Current Data Message-Type")
3431 }
3432 omci.AttributeMask = binary.BigEndian.Uint16(data[4:6])
3433
Matteo Scandolof9d43412021-01-12 11:11:34 -08003434 switch omci.Result {
3435 case me.ProcessingError, me.NotSupported, me.UnknownEntity, me.UnknownInstance, me.DeviceBusy:
3436 return nil // Done (do not try and decode attributes)
3437 }
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003438 // Attribute decode
3439 omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[6:], p, byte(GetCurrentDataResponseType))
3440 if err != nil {
3441 return err
3442 }
3443 return nil
3444}
3445
3446func decodeGetCurrentDataResponse(data []byte, p gopacket.PacketBuilder) error {
3447 omci := &GetCurrentDataResponse{}
3448 omci.MsgLayerType = LayerTypeGetCurrentDataResponse
3449 return decodingLayerDecoder(omci, data, p)
3450}
3451
Matteo Scandolof9d43412021-01-12 11:11:34 -08003452// SerializeTo provides serialization of an Get Current Data Message Type Response
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003453func (omci *GetCurrentDataResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3454 // Basic (common) OMCI Header is 8 octets, 10
3455 err := omci.MeBasePacket.SerializeTo(b)
3456 if err != nil {
3457 return err
3458 }
Matteo Scandolof9d43412021-01-12 11:11:34 -08003459 meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003460 me.ParamData{EntityID: omci.EntityInstance})
Matteo Scandolof9d43412021-01-12 11:11:34 -08003461 if omciErr.StatusCode() != me.Success {
3462 return omciErr.GetError()
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003463 }
3464 // ME needs to support Get
3465 if !me.SupportsMsgType(meDefinition, me.GetCurrentData) {
3466 return me.NewProcessingError("managed entity does not support the Get Current Data Message-Type")
3467 }
3468 bytes, err := b.AppendBytes(2)
3469 if err != nil {
3470 return err
3471 }
3472 binary.BigEndian.PutUint16(bytes[0:2], omci.AttributeMask)
3473
3474 // Attribute serialization
3475 // TODO: Only Baseline supported at this time
3476 bytesAvailable := MaxBaselineLength - 9 - 8
Matteo Scandolof9d43412021-01-12 11:11:34 -08003477 var failedMask uint16
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003478
Matteo Scandolof9d43412021-01-12 11:11:34 -08003479 err, failedMask = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b,
3480 byte(GetCurrentDataResponseType), bytesAvailable, opts.FixLengths)
3481
3482 if failedMask != 0 {
3483 // TODO: See GetResponse serialization above for the steps here
3484 return me.NewMessageTruncatedError("getCurrentData attribute truncation not yet supported")
3485 }
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003486 if err != nil {
3487 return err
3488 }
3489 return nil
3490}
3491
3492/////////////////////////////////////////////////////////////////////////////
3493//
3494type SetTableRequest struct {
3495 MeBasePacket
3496 // TODO: Fix me when extended messages supported)
3497}
3498
3499func (omci *SetTableRequest) String() string {
3500 return fmt.Sprintf("%v", omci.MeBasePacket.String())
3501}
3502
Matteo Scandolof9d43412021-01-12 11:11:34 -08003503// DecodeFromBytes decodes the given bytes of a Set Table Request into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003504func (omci *SetTableRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3505 // Common ClassID/EntityID decode in msgBase
3506 err := omci.MeBasePacket.DecodeFromBytes(data, p)
3507 if err != nil {
3508 return err
3509 }
3510 return errors.New("need to implement") // TODO: Fix me when extended messages supported)
3511}
3512
3513func decodeSetTableRequest(data []byte, p gopacket.PacketBuilder) error {
3514 omci := &SetTableRequest{}
3515 omci.MsgLayerType = LayerTypeSetTableRequest
3516 return decodingLayerDecoder(omci, data, p)
3517}
3518
Matteo Scandolof9d43412021-01-12 11:11:34 -08003519// SerializeTo provides serialization of an Set Table Message Type Request
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003520func (omci *SetTableRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3521 // Basic (common) OMCI Header is 8 octets, 10
3522 err := omci.MeBasePacket.SerializeTo(b)
3523 if err != nil {
3524 return err
3525 }
3526 return errors.New("need to implement") /// TODO: Fix me when extended messages supported)
3527}
3528
3529/////////////////////////////////////////////////////////////////////////////
3530//
3531type SetTableResponse struct {
3532 MeBasePacket
3533 // TODO: Fix me when extended messages supported)
3534}
3535
3536func (omci *SetTableResponse) String() string {
3537 return fmt.Sprintf("%v", omci.MeBasePacket.String())
3538}
3539
Matteo Scandolof9d43412021-01-12 11:11:34 -08003540// DecodeFromBytes decodes the given bytes of a Set Table Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003541func (omci *SetTableResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3542 // Common ClassID/EntityID decode in msgBase
3543 err := omci.MeBasePacket.DecodeFromBytes(data, p)
3544 if err != nil {
3545 return err
3546 }
3547 return errors.New("need to implement") // TODO: Fix me when extended messages supported)
3548}
3549
3550func decodeSetTableResponse(data []byte, p gopacket.PacketBuilder) error {
3551 omci := &SetTableResponse{}
3552 omci.MsgLayerType = LayerTypeSetTableResponse
3553 return decodingLayerDecoder(omci, data, p)
3554}
3555
Matteo Scandolof9d43412021-01-12 11:11:34 -08003556// SerializeTo provides serialization of an Set Table Message Type Response
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003557func (omci *SetTableResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3558 // Basic (common) OMCI Header is 8 octets, 10
3559 err := omci.MeBasePacket.SerializeTo(b)
3560 if err != nil {
3561 return err
3562 }
3563 return errors.New("need to implement") // TODO: Fix me when extended messages supported)
3564}
3565
3566/////////////////////////////////////////////////////////////////////////////
3567//
3568type UnsupportedMessageTypeResponse struct {
3569 MeBasePacket
3570 Result me.Results
3571}
3572
Matteo Scandolof9d43412021-01-12 11:11:34 -08003573// DecodeFromBytes decodes the given bytes of an Unsupported Message Type Response into this layer
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003574func (omci *UnsupportedMessageTypeResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
3575 return errors.New("you should never really decode this")
3576}
3577
Matteo Scandolof9d43412021-01-12 11:11:34 -08003578// SerializeTo provides serialization of an Unsupported Message Type Response
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07003579func (omci *UnsupportedMessageTypeResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
3580 // Basic (common) OMCI Header is 8 octets, 10
3581 err := omci.MeBasePacket.SerializeTo(b)
3582 if err != nil {
3583 return err
3584 }
3585 bytes, err := b.AppendBytes(1)
3586 if err != nil {
3587 return err
3588 }
3589 bytes[0] = byte(omci.Result)
3590 return nil
3591}