blob: c42e0915b789a74bfce3b5126fb540559c2f126e [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14/*
15 * NOTE: This file was generated, manual edits will be overwritten!
16 *
17 * Generated by 'goCodeGenerator.py':
18 * https://github.com/cboling/OMCI-parser/README.md
19 */
20package omci
21
22import (
23 "errors"
24 "fmt"
25 me "github.com/cboling/omci/generated"
26 "github.com/deckarep/golang-set"
27 "github.com/google/gopacket"
28 "time"
29)
30
31var encoderMap map[MessageType]func(*me.ManagedEntity, options) (gopacket.SerializableLayer, error)
32
33func init() {
34 encoderMap = make(map[MessageType]func(*me.ManagedEntity, options) (gopacket.SerializableLayer, error))
35
36 encoderMap[CreateRequestType] = CreateRequestFrame
37 encoderMap[DeleteRequestType] = DeleteRequestFrame
38 encoderMap[SetRequestType] = SetRequestFrame
39 encoderMap[GetRequestType] = GetRequestFrame
40 encoderMap[GetAllAlarmsRequestType] = GetAllAlarmsRequestFrame
41 encoderMap[GetAllAlarmsNextRequestType] = GetAllAlarmsNextRequestFrame
42 encoderMap[MibUploadRequestType] = MibUploadRequestFrame
43 encoderMap[MibUploadNextRequestType] = MibUploadNextRequestFrame
44 encoderMap[MibResetRequestType] = MibResetRequestFrame
45 encoderMap[TestRequestType] = TestRequestFrame
46 encoderMap[StartSoftwareDownloadRequestType] = StartSoftwareDownloadRequestFrame
47 encoderMap[DownloadSectionRequestType] = DownloadSectionRequestFrame
48 encoderMap[EndSoftwareDownloadRequestType] = EndSoftwareDownloadRequestFrame
49 encoderMap[ActivateSoftwareRequestType] = ActivateSoftwareRequestFrame
50 encoderMap[CommitSoftwareRequestType] = CommitSoftwareRequestFrame
51 encoderMap[SynchronizeTimeRequestType] = SynchronizeTimeRequestFrame
52 encoderMap[RebootRequestType] = RebootRequestFrame
53 encoderMap[GetNextRequestType] = GetNextRequestFrame
54 encoderMap[GetCurrentDataRequestType] = GetCurrentDataRequestFrame
55 encoderMap[SetTableRequestType] = SetTableRequestFrame
56 encoderMap[CreateResponseType] = CreateResponseFrame
57 encoderMap[DeleteResponseType] = DeleteResponseFrame
58 encoderMap[SetResponseType] = SetResponseFrame
59 encoderMap[GetResponseType] = GetResponseFrame
60 encoderMap[GetAllAlarmsResponseType] = GetAllAlarmsResponseFrame
61 encoderMap[GetAllAlarmsNextResponseType] = GetAllAlarmsNextResponseFrame
62 encoderMap[MibUploadResponseType] = MibUploadResponseFrame
63 encoderMap[MibUploadNextResponseType] = MibUploadNextResponseFrame
64 encoderMap[MibResetResponseType] = MibResetResponseFrame
65 encoderMap[TestResponseType] = TestResponseFrame
66 encoderMap[StartSoftwareDownloadResponseType] = StartSoftwareDownloadResponseFrame
67 encoderMap[DownloadSectionResponseType] = DownloadSectionResponseFrame
68 encoderMap[EndSoftwareDownloadResponseType] = EndSoftwareDownloadResponseFrame
69 encoderMap[ActivateSoftwareResponseType] = ActivateSoftwareResponseFrame
70 encoderMap[CommitSoftwareResponseType] = CommitSoftwareResponseFrame
71 encoderMap[SynchronizeTimeResponseType] = SynchronizeTimeResponseFrame
72 encoderMap[RebootResponseType] = RebootResponseFrame
73 encoderMap[GetNextResponseType] = GetNextResponseFrame
74 encoderMap[GetCurrentDataResponseType] = GetCurrentDataResponseFrame
75 encoderMap[SetTableResponseType] = SetTableResponseFrame
76 encoderMap[AlarmNotificationType] = AlarmNotificationFrame
77 encoderMap[AttributeValueChangeType] = AttributeValueChangeFrame
78 encoderMap[TestResultType] = TestResultFrame
79}
80
81type options struct {
82 frameFormat DeviceIdent
83 failIfTruncated bool
84 attributeMask uint16
85 result me.Results // Common for many responses
86 attrExecutionMask uint16 // Create Response Only if results == 3 or Set Response only if results == 0
87 unsupportedMask uint16 // Set Response only if results == 9
88 sequenceNumberCountOrSize uint16 // For get-next request frames and for frames that return number of commands or length
89 transactionID uint16 // OMCI TID
90 mode uint8 // Get All Alarms retrieval mode
91 alarm AlarmOptions // Alarm related frames
92 software SoftwareOptions // Software image related frames
93 payload interface{} // ME or list of MEs, alarm bitmap, timestamp, ...
94}
95
96var defaultFrameOptions = options{
97 frameFormat: BaselineIdent,
98 failIfTruncated: false,
99 attributeMask: 0xFFFF,
100 result: me.Success,
101 attrExecutionMask: 0,
102 unsupportedMask: 0,
103 sequenceNumberCountOrSize: 0,
104 transactionID: 0,
105 mode: 0,
106 software: defaultSoftwareOptions,
107 alarm: defaultAlarmOptions,
108 payload: nil,
109}
110
111// FrameOption sets options such as frame format, etc.
112type FrameOption func(*options)
113
114// FrameFormat determines determines the OMCI message format used on the fiber.
115// The default value is BaselineIdent
116func FrameFormat(ff DeviceIdent) FrameOption {
117 return func(o *options) {
118 o.frameFormat = ff
119 }
120}
121
122// FailIfTruncated determines whether a request to encode a frame that does
123// not have enough room for all requested options should fail and return an
124// error.
125//
126// If set to 'false', the behaviour depends on the message type/operation
127// requested. The table below provides more information:
128//
129// Request Type Behavour
130// ------------------------------------------------------------------------
131// CreateRequest A single CreateRequest struct is always returned as the
132// CreateRequest message does not have an attributes Mask
133// field and a Baseline OMCI message is large enough to
134// support all Set-By-Create attributes.
135//
136// GetResponse If multiple OMCI response frames are needed to return
137// all requested attributes, only the attributes that can
138// fit will be returned and the FailedAttributeMask field
139// set to the attributes that could not be returned
140//
141// If this is an ME with an attribute that is a table, the
142// first GetResponse struct will return the size of the
143// attribute and the following GetNextResponse structs will
144// contain the attribute data. The ONU application is
145// responsible for stashing these extra struct(s) away in
146// anticipation of possible GetNext Requests occurring for
147// the attribute. See the discussion on Table attributes
148// in the GetResponse section of ITU G.988 for more
149// information.
150//
151// If set to 'true', no struct(s) are returned and an error is provided.
152//
153// The default value is 'false'
154func FailIfTruncated(f bool) FrameOption {
155 return func(o *options) {
156 o.failIfTruncated = f
157 }
158}
159
160// attributeMask determines the attributes to encode into the frame.
161// The default value is 0xFFFF which specifies all available attributes
162// in the frame
163func AttributeMask(m uint16) FrameOption {
164 return func(o *options) {
165 o.attributeMask = m
166 }
167}
168
169// AttributeExecutionMask is used by the Create and Set Response frames to indicate
170// attributes that failed to be created/set.
171func AttributeExecutionMask(m uint16) FrameOption {
172 return func(o *options) {
173 o.attrExecutionMask = m
174 }
175}
176
177// UnsupportedAttributeMask is used by the Set Response frames to indicate
178// attributes are not supported on this ONU
179func UnsupportedAttributeMask(m uint16) FrameOption {
180 return func(o *options) {
181 o.unsupportedMask = m
182 }
183}
184
185// Result is used to set returned results in responses
186// that have that field
187func Result(r me.Results) FrameOption {
188 return func(o *options) {
189 o.result = r
190 }
191}
192
193// SequenceNumberCountOrSize is used by the GetNext and MibUploadGetNext request frames and for
194// frames that return number of commands or length such as Get (table attribute) or
195// MibUpload/GetAllAlarms/...
196func SequenceNumberCountOrSize(m uint16) FrameOption {
197 return func(o *options) {
198 o.sequenceNumberCountOrSize = m
199 }
200}
201
202// TransactionID is to specify the TID in the OMCI header. The default is
203// zero which requires the caller to set it to the appropriate value if this
204// is not an autonomous ONU notification frame
205func TransactionID(tid uint16) FrameOption {
206 return func(o *options) {
207 o.transactionID = tid
208 }
209}
210
211// RetrievalMode is to specify the the Alarm Retrieval Mode in a GetAllAlarms Request
212func RetrievalMode(m uint8) FrameOption {
213 return func(o *options) {
214 o.mode = m
215 }
216}
217
218// SuccessResult is to specify the the SuccessResult for a SynchronizeTime Response
219func SuccessResult(m uint8) FrameOption {
220 return func(o *options) {
221 o.mode = m
222 }
223}
224
225// RebootCondition is to specify the the Reboot Condition for a ONU Reboot request
226func RebootCondition(m uint8) FrameOption {
227 return func(o *options) {
228 o.mode = m
229 }
230}
231
232// Alarm is used to specify a collection of options related to Alarm notifications
233func Alarm(ao AlarmOptions) FrameOption {
234 return func(o *options) {
235 o.alarm = ao
236 }
237}
238
239// Software is used to specify a collection of options related to Software image
240// manipulation
241func Software(so SoftwareOptions) FrameOption {
242 return func(o *options) {
243 o.software = so
244 }
245}
246
247// Payload is used to specify ME payload options that are not simple types. This
248// include the ME (list of MEs) to encode into a GetNextMibUpload response, the
249// alarm bitmap for alarm relates responses/notifications, alarm bitmaps, and
250// for specifying the download section data when performing Software Download.
251func Payload(p interface{}) FrameOption {
252 return func(o *options) {
253 o.payload = p
254 }
255}
256
257// Alarm related frames have a wide variety of settable values. Placing them
258// in a separate struct is mainly to keep the base options simple
259type AlarmOptions struct {
260 AlarmClassId me.ClassID
261 AlarmInstance uint16
262 AlarmBitmap []byte // Should be up to 58 octets
263}
264
265var defaultAlarmOptions = AlarmOptions{
266 AlarmClassId: 0,
267 AlarmInstance: 0,
268 AlarmBitmap: nil,
269}
270
271// Software related frames have a wide variety of settable values. Placing them
272// in a separate struct is mainly to keep the base options simple
273type SoftwareOptions struct {
274 WindowSize uint8 // Window size - 1
275 ImageSize uint32
276 CircuitPacks []uint16 // slot (upper 8 bits) and instance (lower 8 bits)
277 Results []downloadResults
278}
279
280var defaultSoftwareOptions = SoftwareOptions{
281 WindowSize: 0,
282 ImageSize: 0,
283 CircuitPacks: nil,
284 Results: nil,
285}
286
287// EncodeFrame will encode the Managed Entity specific protocol struct and an
288// OMCILayer struct. This struct can be provided to the gopacket.SerializeLayers()
289// function to be serialized into a buffer for transmission.
290func EncodeFrame(m *me.ManagedEntity, messageType MessageType, opt ...FrameOption) (*OMCI, gopacket.SerializableLayer, error) {
291 // Check for message type support
292 msgType := me.MsgType(messageType & me.MsgTypeMask)
293 meDefinition := m.GetManagedEntityDefinition()
294
295 if !me.SupportsMsgType(meDefinition, msgType) {
296 msg := fmt.Sprintf("managed entity %v does not support %v Message-Type",
297 meDefinition.GetName(), msgType)
298 return nil, nil, errors.New(msg)
299 }
300 // Decode options
301 opts := defaultFrameOptions
302 for _, o := range opt {
303 o(&opts)
304 }
305 // TODO: If AttributesMask option passed in, check for deprecated options. Allow encoding option
306 // that will ignore deprecated option. Add additional in the get and set meframe_test,go
307 // test functions to test this. Also have it test attribute name(s) to see if the attribute
308 // is deprecated. The OMCI-Parser will need to decode deprecated for us...
309 // Note: Transaction ID should be set before frame serialization
310 omci := &OMCI{
311 TransactionID: opts.transactionID,
312 MessageType: messageType,
313 DeviceIdentifier: opts.frameFormat,
314 }
315 var meInfo gopacket.SerializableLayer
316 var err error
317
318 if encoder, ok := encoderMap[messageType]; ok {
319 meInfo, err = encoder(m, opts)
320 } else {
321 err = errors.New(fmt.Sprintf("message-type: %v/%#x is not supported", messageType, messageType))
322 }
323 if err != nil {
324 return nil, nil, err
325 }
326 return omci, meInfo, err
327}
328
329// For most all create methods below, error checking for valid masks, attribute
330// values, and other fields is left to when the frame is actually serialized.
331
332func checkAttributeMask(m *me.ManagedEntity, mask uint16) (uint16, error) {
333 if mask == defaultFrameOptions.attributeMask {
334 // Scale back to just what is allowed
335 return m.GetAllowedAttributeMask(), nil
336 }
337 if mask&m.GetManagedEntityDefinition().GetAllowedAttributeMask() != mask {
338 return 0, errors.New("invalid attribute mask")
339 }
340 return mask & m.GetManagedEntityDefinition().GetAllowedAttributeMask(), nil
341}
342
343// return the maximum space that can be used by attributes
344func maxPacketAvailable(m *me.ManagedEntity, opt options) uint {
345 if opt.frameFormat == BaselineIdent {
346 // OMCI Header - 4 octets
347 // Class ID/Instance ID - 4 octets
348 // Length field - 4 octets
349 // MIC - 4 octets
350 return MaxBaselineLength - 16
351 }
352 // OMCI Header - 4 octets
353 // Class ID/Instance ID - 4 octets
354 // Length field - 4 octets
355 // MIC - 4 octets
356 return MaxExtendedLength - 16
357}
358
359func calculateAttributeMask(m *me.ManagedEntity, requestedMask uint16) (uint16, error) {
360 attrDefs := m.GetAttributeDefinitions()
361 var entityIdName string
362 if entry, ok := (*attrDefs)[0]; ok {
363 entityIdName = entry.GetName()
364 } else {
365 panic("unexpected error") // All attribute definition maps have an entity ID
366 }
367 attributeNames := make([]interface{}, 0)
368 for attrName := range *m.GetAttributeValueMap() {
369 if attrName == entityIdName {
370 continue // No mask for EntityID
371 }
372 attributeNames = append(attributeNames, attrName)
373 }
374 calculatedMask, err := me.GetAttributeBitmap(*attrDefs, mapset.NewSetWith(attributeNames...))
375
376 if err != nil {
377 return 0, err
378 }
379 return calculatedMask & requestedMask, nil
380}
381
382// GenFrame is a helper function to make tests a little easier to read.
383// For a real application, use the .../omci/generated/class.go 'New'
384// functions to create your Managed Entity and then use it to call the
385// EncodeFrame method.
386func GenFrame(meInstance *me.ManagedEntity, messageType MessageType, options ...FrameOption) ([]byte, error) {
387 omciLayer, msgLayer, err := EncodeFrame(meInstance, messageType, options...)
388 if err != nil {
389 return nil, err
390 }
391 // Serialize the frame and send it
392 var serializeOptions gopacket.SerializeOptions
393 serializeOptions.FixLengths = true
394
395 buffer := gopacket.NewSerializeBuffer()
396 err = gopacket.SerializeLayers(buffer, serializeOptions, omciLayer, msgLayer)
397 if err != nil {
398 return nil, err
399 }
400 return buffer.Bytes(), nil
401}
402
403func CreateRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
404 // NOTE: The OMCI parser does not extract the default values of set-by-create attributes
405 // and are the zero 'default' (or nil) at this time. For this reason, make sure
406 // you specify all non-zero default values and pass them in appropriate
407 meLayer := &CreateRequest{
408 MeBasePacket: MeBasePacket{
409 EntityClass: m.GetClassID(),
410 EntityInstance: m.GetEntityID(),
411 },
412 Attributes: *m.GetAttributeValueMap(),
413 }
414 return meLayer, nil
415}
416
417func CreateResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
418 meLayer := &CreateResponse{
419 MeBasePacket: MeBasePacket{
420 EntityClass: m.GetClassID(),
421 EntityInstance: m.GetEntityID(),
422 },
423 Result: opt.result,
424 AttributeExecutionMask: opt.attributeMask,
425 }
426 if meLayer.Result == me.ParameterError {
427 meLayer.AttributeExecutionMask = opt.attrExecutionMask
428 }
429 return meLayer, nil
430}
431
432func DeleteRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
433 meLayer := &DeleteRequest{
434 MeBasePacket: MeBasePacket{
435 EntityClass: m.GetClassID(),
436 EntityInstance: m.GetEntityID(),
437 },
438 }
439 return meLayer, nil
440}
441
442func DeleteResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
443 meLayer := &DeleteResponse{
444 MeBasePacket: MeBasePacket{
445 EntityClass: m.GetClassID(),
446 EntityInstance: m.GetEntityID(),
447 },
448 Result: opt.result,
449 }
450 return meLayer, nil
451}
452
453func SetRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
454 mask, err := checkAttributeMask(m, opt.attributeMask)
455 if err != nil {
456 return nil, err
457 }
458 mask, err = calculateAttributeMask(m, mask)
459 if err != nil {
460 return nil, err
461 }
462 meDefinition := m.GetManagedEntityDefinition()
463 attrDefs := *meDefinition.GetAttributeDefinitions()
464 attrMap := *m.GetAttributeValueMap()
465
466 // Get payload space available
467 maxPayload := maxPacketAvailable(m, opt)
468 payloadAvailable := int(maxPayload) - 2 // Less attribute mask
469
470 meLayer := &SetRequest{
471 MeBasePacket: MeBasePacket{
472 EntityClass: m.GetClassID(),
473 EntityInstance: m.GetEntityID(),
474 },
475 AttributeMask: 0,
476 Attributes: make(me.AttributeValueMap),
477 }
478 for mask != 0 {
479 // Iterate down the attributes (Attribute 0 is the ManagedEntity ID)
480 var attrIndex uint
481 for attrIndex = 1; attrIndex <= 16; attrIndex++ {
482 // Is this attribute requested
483 if mask&(1<<(16-attrIndex)) != 0 {
484 // Get definitions since we need the name
485 attrDef, ok := attrDefs[attrIndex]
486 if !ok {
487 msg := fmt.Sprintf("Unexpected error, index %v not valued for ME %v",
488 attrIndex, meDefinition.GetName())
489 return nil, errors.New(msg)
490 }
491 var attrValue interface{}
492 attrValue, ok = attrMap[attrDef.Name]
493 if !ok {
494 msg := fmt.Sprintf("Unexpected error, attribute %v not provided in ME %v: %v",
495 attrDef.GetName(), meDefinition.GetName(), m)
496 return nil, errors.New(msg)
497 }
498 // Is space available?
499 if attrDef.Size <= payloadAvailable {
500 // Mark bit handled
501 mask &= ^(1 << (16 - attrIndex))
502 meLayer.AttributeMask |= 1 << (16 - attrIndex)
503 meLayer.Attributes[attrDef.Name] = attrValue
504 payloadAvailable -= attrDef.Size
505 } else {
506 // TODO: Should we set truncate?
507 msg := fmt.Sprintf("out-of-space. Cannot fit attribute %v into SetRequest message",
508 attrDef.GetName())
509 return nil, me.NewMessageTruncatedError(msg)
510 }
511 }
512 }
513 }
514 if err == nil && meLayer.AttributeMask == 0 {
515 // TODO: Is a set request with no attributes valid?
516 return nil, errors.New("no attributes encoded for SetRequest")
517 }
518 return meLayer, nil
519}
520
521func SetResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
522 meLayer := &SetResponse{
523 MeBasePacket: MeBasePacket{
524 EntityClass: m.GetClassID(),
525 EntityInstance: m.GetEntityID(),
526 },
527 Result: opt.result,
528 }
529 if meLayer.Result == me.AttributeFailure {
530 meLayer.UnsupportedAttributeMask = opt.unsupportedMask
531 meLayer.FailedAttributeMask = opt.attrExecutionMask
532 }
533 return meLayer, nil
534}
535
536func GetRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
537 // Given mask sent in (could be default of 0xFFFF) get what is allowable.
538 // This will be all allowed if 0xFFFF is passed in, or a subset if a fixed
539 // number of items.
540 maxMask, err := checkAttributeMask(m, opt.attributeMask)
541 if err != nil {
542 return nil, err
543 }
544 // Now scan attributes and reduce mask to only those requested
545 var mask uint16
546 mask, err = calculateAttributeMask(m, maxMask)
547 if err != nil {
548 return nil, err
549 }
550 if mask == 0 {
551 // TODO: Is a Get request with no attributes valid?
552 return nil, errors.New("no attributes requested for GetRequest")
553 }
554 meLayer := &GetRequest{
555 MeBasePacket: MeBasePacket{
556 EntityClass: m.GetClassID(),
557 EntityInstance: m.GetEntityID(),
558 },
559 AttributeMask: mask,
560 }
561 return meLayer, nil
562}
563
564func GetResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
565 mask, err := checkAttributeMask(m, opt.attributeMask)
566 if err != nil {
567 return nil, err
568 }
569 mask, err = calculateAttributeMask(m, mask)
570 if err != nil {
571 return nil, err
572 }
573 meLayer := &GetResponse{
574 MeBasePacket: MeBasePacket{
575 EntityClass: m.GetClassID(),
576 EntityInstance: m.GetEntityID(),
577 },
578 Result: opt.result,
579 AttributeMask: 0,
580 Attributes: make(me.AttributeValueMap),
581 }
582 if meLayer.Result == me.AttributeFailure {
583 meLayer.UnsupportedAttributeMask = opt.unsupportedMask
584 meLayer.FailedAttributeMask = opt.attrExecutionMask
585 }
586 // Encode whatever we can
587 if meLayer.Result == me.Success || meLayer.Result == me.AttributeFailure {
588 // Encode results
589 // Get payload space available
590 maxPayload := maxPacketAvailable(m, opt)
591 payloadAvailable := int(maxPayload) - 2 - 4 // Less attribute mask and attribute error encoding
592 meDefinition := m.GetManagedEntityDefinition()
593 attrDefs := *meDefinition.GetAttributeDefinitions()
594 attrMap := *m.GetAttributeValueMap()
595
596 if mask != 0 {
597 // Iterate down the attributes (Attribute 0 is the ManagedEntity ID)
598 var attrIndex uint
599 for attrIndex = 1; attrIndex <= 16; attrIndex++ {
600 // Is this attribute requested
601 if mask&(1<<(16-attrIndex)) != 0 {
602 // Get definitions since we need the name
603 attrDef, ok := attrDefs[attrIndex]
604 if !ok {
605 msg := fmt.Sprintf("Unexpected error, index %v not valued for ME %v",
606 attrIndex, meDefinition.GetName())
607 return nil, errors.New(msg)
608 }
609 var attrValue interface{}
610 attrValue, ok = attrMap[attrDef.Name]
611 if !ok {
612 msg := fmt.Sprintf("Unexpected error, attribute %v not provided in ME %v: %v",
613 attrDef.GetName(), meDefinition.GetName(), m)
614 return nil, errors.New(msg)
615 }
616 // Is space available?
617 if attrDef.Size <= payloadAvailable {
618 // Mark bit handled
619 mask &= ^(1 << (16 - attrIndex))
620 meLayer.AttributeMask |= 1 << (16 - attrIndex)
621 meLayer.Attributes[attrDef.Name] = attrValue
622 payloadAvailable -= attrDef.Size
623
624 } else if opt.failIfTruncated {
625 // TODO: Should we set truncate?
626 msg := fmt.Sprintf("out-of-space. Cannot fit attribute %v into GetResponse message",
627 attrDef.GetName())
628 return nil, me.NewMessageTruncatedError(msg)
629 } else {
630 // Add to existing 'failed' mask and update result
631 meLayer.FailedAttributeMask |= 1 << (16 - attrIndex)
632 meLayer.Result = me.AttributeFailure
633 }
634 }
635 }
636 }
637 }
638 return meLayer, nil
639}
640
641func GetAllAlarmsRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
642 // Common for all MEs
643 meLayer := &GetAllAlarmsRequest{
644 MeBasePacket: MeBasePacket{
645 EntityClass: m.GetClassID(),
646 EntityInstance: m.GetEntityID(),
647 },
648 AlarmRetrievalMode: opt.mode,
649 }
650 return meLayer, nil
651}
652
653func GetAllAlarmsResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
654 // Common for all MEs
655 meLayer := &GetAllAlarmsResponse{
656 MeBasePacket: MeBasePacket{
657 EntityClass: m.GetClassID(),
658 EntityInstance: m.GetEntityID(),
659 },
660 NumberOfCommands: opt.sequenceNumberCountOrSize,
661 }
662 return meLayer, nil
663}
664
665func GetAllAlarmsNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
666 // Common for all MEs
667 meLayer := &GetAllAlarmsNextRequest{
668 MeBasePacket: MeBasePacket{
669 EntityClass: m.GetClassID(),
670 EntityInstance: m.GetEntityID(),
671 },
672 CommandSequenceNumber: opt.sequenceNumberCountOrSize,
673 }
674 return meLayer, nil
675}
676
677func GetAllAlarmsNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
678 // Common for all MEs
679 meLayer := &GetAllAlarmsNextResponse{
680 MeBasePacket: MeBasePacket{
681 EntityClass: m.GetClassID(),
682 EntityInstance: m.GetEntityID(),
683 },
684 AlarmEntityClass: opt.alarm.AlarmClassId,
685 AlarmEntityInstance: opt.alarm.AlarmInstance,
686 }
687 if len(opt.alarm.AlarmBitmap) > 28 {
688 return nil, errors.New("invalid Alarm Bitmap Size. Must be [0..27]")
689 }
690 for octet := 0; octet < len(opt.alarm.AlarmBitmap); octet++ {
691 meLayer.AlarmBitMap[octet] = opt.alarm.AlarmBitmap[octet]
692 }
693 for octet := len(opt.alarm.AlarmBitmap); octet < 28; octet++ {
694 meLayer.AlarmBitMap[octet] = 0
695 }
696 return meLayer, nil
697}
698
699func MibUploadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
700 // Common for all MEs
701 meLayer := &MibUploadRequest{
702 MeBasePacket: MeBasePacket{
703 EntityClass: m.GetClassID(),
704 EntityInstance: 0,
705 },
706 }
707 return meLayer, nil
708}
709
710func MibUploadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
711 // Common for all MEs
712 meLayer := &MibUploadResponse{
713 MeBasePacket: MeBasePacket{
714 EntityClass: m.GetClassID(),
715 EntityInstance: 0,
716 },
717 NumberOfCommands: opt.sequenceNumberCountOrSize,
718 }
719 return meLayer, nil
720}
721
722func MibUploadNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
723 // Common for all MEs
724 meLayer := &MibUploadNextRequest{
725 MeBasePacket: MeBasePacket{
726 EntityClass: m.GetClassID(),
727 EntityInstance: 0,
728 },
729 CommandSequenceNumber: opt.sequenceNumberCountOrSize,
730 }
731 return meLayer, nil
732}
733
734func MibUploadNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
735 // Common for all MEs
736 meLayer := &MibUploadNextResponse{
737 MeBasePacket: MeBasePacket{
738 EntityClass: m.GetClassID(),
739 EntityInstance: m.GetEntityID(),
740 },
741 }
742 if opt.payload == nil {
743 // Shortcut used to specify the request sequence number is out of range, encode
744 // a ME instance with class ID of zero to specify this per ITU G.988
745 meDef := &me.ManagedEntityDefinition{
746 Name: "InvalidSequenceNumberManagedEntity",
747 ClassID: me.ClassID(0),
748 MessageTypes: nil,
749 AttributeDefinitions: make(me.AttributeDefinitionMap),
750 }
751 opt.payload, _ = me.NewManagedEntity(meDef)
752 }
753 if _, ok := opt.payload.(*[]me.ManagedEntity); ok {
754 if opt.frameFormat == BaselineIdent {
755 return nil, errors.New("invalid payload for Baseline message")
756 }
757 // TODO: List of MEs. valid for extended messages only
758 } else if managedEntity, ok := opt.payload.(*me.ManagedEntity); ok {
759 // Single ME
760 meLayer.ReportedME = *managedEntity
761 } else {
762 return nil, errors.New("invalid payload for MibUploadNextResponse frame")
763 }
764 return meLayer, nil
765}
766
767func MibResetRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
768 // Common for all MEs
769 meLayer := &MibResetRequest{
770 MeBasePacket: MeBasePacket{
771 EntityClass: m.GetClassID(),
772 EntityInstance: m.GetEntityID(),
773 },
774 }
775 return meLayer, nil
776}
777
778func MibResetResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
779 // Common for all MEs
780 meLayer := &MibResetResponse{
781 MeBasePacket: MeBasePacket{
782 EntityClass: m.GetClassID(),
783 EntityInstance: m.GetEntityID(),
784 },
785 Result: opt.result,
786 }
787 return meLayer, nil
788}
789
790func AlarmNotificationFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
791 mask, err := checkAttributeMask(m, opt.attributeMask)
792 if err != nil {
793 return nil, err
794 }
795 // Common for all MEs
796 meLayer := &AlarmNotificationMsg{
797 MeBasePacket: MeBasePacket{
798 EntityClass: m.GetClassID(),
799 EntityInstance: m.GetEntityID(),
800 },
801 }
802 // Get payload space available
803 maxPayload := maxPacketAvailable(m, opt)
804 payloadAvailable := int(maxPayload) - 1 // Less alarm sequence number
805
806 // TODO: Lots of work to do
807 fmt.Println(mask, maxPayload, payloadAvailable)
808
809 return meLayer, errors.New("todo: Not implemented")
810}
811
812func AttributeValueChangeFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
813 mask, err := checkAttributeMask(m, opt.attributeMask)
814 if err != nil {
815 return nil, err
816 }
817 // Common for all MEs
818 meLayer := &AttributeValueChangeMsg{
819 MeBasePacket: MeBasePacket{
820 EntityClass: m.GetClassID(),
821 EntityInstance: m.GetEntityID(),
822 },
823 AttributeMask: 0,
824 Attributes: make(me.AttributeValueMap),
825 }
826 // Get payload space available
827 maxPayload := maxPacketAvailable(m, opt)
828 payloadAvailable := int(maxPayload) - 2 // Less attribute mask
829
830 // TODO: Lots of work to do
831
832 fmt.Println(mask, maxPayload, payloadAvailable)
833 return meLayer, errors.New("todo: Not implemented")
834}
835
836func TestRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
837 mask, err := checkAttributeMask(m, opt.attributeMask)
838 if err != nil {
839 return nil, err
840 }
841 // Common for all MEs
842 meLayer := &TestRequest{
843 MeBasePacket: MeBasePacket{
844 EntityClass: m.GetClassID(),
845 EntityInstance: m.GetEntityID(),
846 },
847 }
848 // Get payload space available
849 maxPayload := maxPacketAvailable(m, opt)
850
851 // TODO: Lots of work to do
852
853 fmt.Println(mask, maxPayload)
854 return meLayer, errors.New("todo: Not implemented")
855}
856
857func TestResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
858 mask, err := checkAttributeMask(m, opt.attributeMask)
859 if err != nil {
860 return nil, err
861 }
862 // Common for all MEs
863 meLayer := &TestResponse{
864 MeBasePacket: MeBasePacket{
865 EntityClass: m.GetClassID(),
866 EntityInstance: m.GetEntityID(),
867 },
868 }
869 // Get payload space available
870 maxPayload := maxPacketAvailable(m, opt)
871
872 // TODO: Lots of work to do
873
874 fmt.Println(mask, maxPayload)
875 return meLayer, errors.New("todo: Not implemented")
876}
877
878func StartSoftwareDownloadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
879 // Common for all MEs
880 meLayer := &StartSoftwareDownloadRequest{
881 MeBasePacket: MeBasePacket{
882 EntityClass: m.GetClassID(),
883 EntityInstance: m.GetEntityID(),
884 },
885 WindowSize: opt.software.WindowSize,
886 ImageSize: opt.software.ImageSize,
887 NumberOfCircuitPacks: byte(len(opt.software.CircuitPacks)),
888 CircuitPacks: opt.software.CircuitPacks,
889 }
890 // TODO: Add length check to insure we do not exceed maximum packet size
891 // payloadAvailable := int(maxPacketAvailable(m, opt))
892 payloadAvailable := 2
893 sizeNeeded := 1
894 if sizeNeeded > payloadAvailable {
895 // TODO: Should we set truncate?
896 msg := "out-of-space. Cannot fit Circuit Pack instances into Start Software Download Request message"
897 return nil, me.NewMessageTruncatedError(msg)
898 }
899 return meLayer, nil
900}
901
902func StartSoftwareDownloadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
903 // Common for all MEs
904 meLayer := &StartSoftwareDownloadResponse{
905 MeBasePacket: MeBasePacket{
906 EntityClass: m.GetClassID(),
907 EntityInstance: m.GetEntityID(),
908 },
909 WindowSize: opt.software.WindowSize,
910 NumberOfInstances: byte(len(opt.software.CircuitPacks)),
911 MeResults: opt.software.Results,
912 }
913 // TODO: Add length check to insure we do not exceed maximum packet size
914 // payloadAvailable := int(maxPacketAvailable(m, opt))
915 payloadAvailable := 2
916 sizeNeeded := 1
917 if sizeNeeded > payloadAvailable {
918 // TODO: Should we set truncate?
919 msg := "out-of-space. Cannot fit Results into Start Software Download Response message"
920 return nil, me.NewMessageTruncatedError(msg)
921 }
922 return meLayer, nil
923}
924
925func DownloadSectionRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
926 mask, err := checkAttributeMask(m, opt.attributeMask)
927 if err != nil {
928 return nil, err
929 }
930 // Common for all MEs
931 meLayer := &DownloadSectionRequest{
932 MeBasePacket: MeBasePacket{
933 EntityClass: m.GetClassID(),
934 EntityInstance: m.GetEntityID(),
935 },
936 }
937 // Get payload space available
938 maxPayload := maxPacketAvailable(m, opt)
939
940 // TODO: Lots of work to do
941
942 fmt.Println(mask, maxPayload)
943 return meLayer, errors.New("todo: Not implemented")
944}
945
946func DownloadSectionResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
947 mask, err := checkAttributeMask(m, opt.attributeMask)
948 if err != nil {
949 return nil, err
950 }
951 // Common for all MEs
952 meLayer := &DownloadSectionResponse{
953 MeBasePacket: MeBasePacket{
954 EntityClass: m.GetClassID(),
955 EntityInstance: m.GetEntityID(),
956 },
957 }
958 // Get payload space available
959 maxPayload := maxPacketAvailable(m, opt)
960
961 // TODO: Lots of work to do
962
963 fmt.Println(mask, maxPayload)
964 return meLayer, errors.New("todo: Not implemented")
965}
966
967func EndSoftwareDownloadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
968 mask, err := checkAttributeMask(m, opt.attributeMask)
969 if err != nil {
970 return nil, err
971 }
972 // Common for all MEs
973 meLayer := &EndSoftwareDownloadRequest{
974 MeBasePacket: MeBasePacket{
975 EntityClass: m.GetClassID(),
976 EntityInstance: m.GetEntityID(),
977 },
978 }
979 // Get payload space available
980 maxPayload := maxPacketAvailable(m, opt)
981
982 // TODO: Lots of work to do
983
984 fmt.Println(mask, maxPayload)
985 return meLayer, errors.New("todo: Not implemented")
986}
987
988func EndSoftwareDownloadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
989 mask, err := checkAttributeMask(m, opt.attributeMask)
990 if err != nil {
991 return nil, err
992 }
993 // Common for all MEs
994 meLayer := &EndSoftwareDownloadResponse{
995 MeBasePacket: MeBasePacket{
996 EntityClass: m.GetClassID(),
997 EntityInstance: m.GetEntityID(),
998 },
999 }
1000 // Get payload space available
1001 maxPayload := maxPacketAvailable(m, opt)
1002
1003 // TODO: Lots of work to do
1004
1005 fmt.Println(mask, maxPayload)
1006 return meLayer, errors.New("todo: Not implemented")
1007}
1008
1009func ActivateSoftwareRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1010 mask, err := checkAttributeMask(m, opt.attributeMask)
1011 if err != nil {
1012 return nil, err
1013 }
1014 // Common for all MEs
1015 meLayer := &ActivateSoftwareRequest{
1016 MeBasePacket: MeBasePacket{
1017 EntityClass: m.GetClassID(),
1018 EntityInstance: m.GetEntityID(),
1019 },
1020 }
1021 // Get payload space available
1022 maxPayload := maxPacketAvailable(m, opt)
1023
1024 // TODO: Lots of work to do
1025
1026 fmt.Println(mask, maxPayload)
1027 return meLayer, errors.New("todo: Not implemented")
1028}
1029
1030func ActivateSoftwareResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1031 mask, err := checkAttributeMask(m, opt.attributeMask)
1032 if err != nil {
1033 return nil, err
1034 }
1035 // Common for all MEs
1036 meLayer := &ActivateSoftwareResponse{
1037 MeBasePacket: MeBasePacket{
1038 EntityClass: m.GetClassID(),
1039 EntityInstance: m.GetEntityID(),
1040 },
1041 }
1042 // Get payload space available
1043 maxPayload := maxPacketAvailable(m, opt)
1044
1045 // TODO: Lots of work to do
1046
1047 fmt.Println(mask, maxPayload)
1048 return meLayer, errors.New("todo: Not implemented")
1049}
1050
1051func CommitSoftwareRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1052 mask, err := checkAttributeMask(m, opt.attributeMask)
1053 if err != nil {
1054 return nil, err
1055 }
1056 // Common for all MEs
1057 meLayer := &CommitSoftwareRequest{
1058 MeBasePacket: MeBasePacket{
1059 EntityClass: m.GetClassID(),
1060 EntityInstance: m.GetEntityID(),
1061 },
1062 }
1063 // Get payload space available
1064 maxPayload := maxPacketAvailable(m, opt)
1065
1066 // TODO: Lots of work to do
1067
1068 fmt.Println(mask, maxPayload)
1069 return meLayer, errors.New("todo: Not implemented")
1070}
1071
1072func CommitSoftwareResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1073 mask, err := checkAttributeMask(m, opt.attributeMask)
1074 if err != nil {
1075 return nil, err
1076 }
1077 // Common for all MEs
1078 meLayer := &CommitSoftwareResponse{
1079 MeBasePacket: MeBasePacket{
1080 EntityClass: m.GetClassID(),
1081 EntityInstance: m.GetEntityID(),
1082 },
1083 }
1084 // Get payload space available
1085 maxPayload := maxPacketAvailable(m, opt)
1086
1087 // TODO: Lots of work to do
1088
1089 fmt.Println(mask, maxPayload)
1090 return meLayer, errors.New("todo: Not implemented")
1091}
1092
1093func SynchronizeTimeRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1094 // Common for all MEs
1095 meLayer := &SynchronizeTimeRequest{
1096 MeBasePacket: MeBasePacket{
1097 EntityClass: m.GetClassID(),
1098 EntityInstance: m.GetEntityID(),
1099 },
1100 }
1101 // Decode payload option. If nil, no timestamp provided
1102 if timestamp, ok := opt.payload.(int64); ok {
1103 tm := time.Unix(timestamp, 0)
1104 meLayer.Year = uint16(tm.UTC().Year())
1105 meLayer.Month = uint8(tm.UTC().Month())
1106 meLayer.Day = uint8(tm.UTC().Day())
1107 meLayer.Hour = uint8(tm.UTC().Hour())
1108 meLayer.Minute = uint8(tm.UTC().Minute())
1109 meLayer.Second = uint8(tm.UTC().Second())
1110 }
1111 return meLayer, nil
1112}
1113
1114func SynchronizeTimeResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1115 // Common for all MEs
1116 meLayer := &SynchronizeTimeResponse{
1117 MeBasePacket: MeBasePacket{
1118 EntityClass: m.GetClassID(),
1119 EntityInstance: m.GetEntityID(),
1120 },
1121 Result: opt.result,
1122 SuccessResults: opt.mode,
1123 }
1124 return meLayer, nil
1125}
1126
1127func RebootRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1128 // Common for all MEs
1129 meLayer := &RebootRequest{
1130 MeBasePacket: MeBasePacket{
1131 EntityClass: m.GetClassID(),
1132 EntityInstance: m.GetEntityID(),
1133 },
1134 RebootCondition: opt.mode,
1135 }
1136 return meLayer, nil
1137}
1138
1139func RebootResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1140 // Common for all MEs
1141 meLayer := &RebootResponse{
1142 MeBasePacket: MeBasePacket{
1143 EntityClass: m.GetClassID(),
1144 EntityInstance: m.GetEntityID(),
1145 },
1146 Result: opt.result,
1147 }
1148 return meLayer, nil
1149}
1150
1151func GetNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1152 // Validate attribute mask
1153 mask, err := checkAttributeMask(m, opt.attributeMask)
1154 if err != nil {
1155 return nil, err
1156 }
1157 // Now scan attributes and reduce mask to only those requested
1158 mask, err = calculateAttributeMask(m, mask)
1159 if err != nil {
1160 return nil, err
1161 }
1162 if mask == 0 {
1163 return nil, errors.New("no attributes requested for GetNextRequest")
1164 }
1165 // TODO: If more than one attribute or the attribute requested is not a table attribute, return an error
1166 // Common for all MEs
1167 meLayer := &GetNextRequest{
1168 MeBasePacket: MeBasePacket{
1169 EntityClass: m.GetClassID(),
1170 EntityInstance: m.GetEntityID(),
1171 },
1172 AttributeMask: mask,
1173 SequenceNumber: opt.sequenceNumberCountOrSize,
1174 }
1175 return meLayer, nil
1176}
1177
1178func GetNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1179 // Validate attribute mask
1180 mask, err := checkAttributeMask(m, opt.attributeMask)
1181 if err != nil {
1182 return nil, err
1183 }
1184 mask, err = calculateAttributeMask(m, mask)
1185 if err != nil {
1186 return nil, err
1187 }
1188 //
1189 // Common for all MEs
1190 meLayer := &GetNextResponse{
1191 MeBasePacket: MeBasePacket{
1192 EntityClass: m.GetClassID(),
1193 EntityInstance: m.GetEntityID(),
1194 },
1195 Result: opt.result,
1196 AttributeMask: 0,
1197 Attributes: make(me.AttributeValueMap),
1198 }
1199 if meLayer.Result == me.Success {
1200 // Get payload space available
1201 maxPayload := maxPacketAvailable(m, opt)
1202 payloadAvailable := int(maxPayload) - 3 // Less results and attribute mask
1203 meDefinition := m.GetManagedEntityDefinition()
1204 attrDefs := *meDefinition.GetAttributeDefinitions()
1205 attrMap := *m.GetAttributeValueMap()
1206
1207 if mask == 0 {
1208 return nil, errors.New("no attributes requested for GetNextResponse")
1209 }
1210 // TODO: If more than one attribute or the attribute requested is not a table attribute, return an error
1211 // Iterate down the attributes (Attribute 0 is the ManagedEntity ID)
1212 var attrIndex uint
1213 for attrIndex = 1; attrIndex <= 16; attrIndex++ {
1214 // Is this attribute requested
1215 if mask&(1<<(16-attrIndex)) != 0 {
1216 // Get definitions since we need the name
1217 attrDef, ok := attrDefs[attrIndex]
1218 if !ok {
1219 msg := fmt.Sprintf("Unexpected error, index %v not valued for ME %v",
1220 attrIndex, meDefinition.GetName())
1221 return nil, errors.New(msg)
1222 }
1223 var attrValue interface{}
1224 attrValue, ok = attrMap[attrDef.Name]
1225 if !ok || attrValue == nil {
1226 msg := fmt.Sprintf("Unexpected error, attribute %v not provided in ME %v: %v",
1227 attrDef.GetName(), meDefinition.GetName(), m)
1228 return nil, errors.New(msg)
1229 }
1230 // Is space available?
1231 if attrDef.Size <= payloadAvailable {
1232 // Mark bit handled
1233 mask &= ^(1 << (16 - attrIndex))
1234 meLayer.AttributeMask |= 1 << (16 - attrIndex)
1235 meLayer.Attributes[attrDef.Name] = attrValue
1236 payloadAvailable -= attrDef.Size
1237 } else {
1238 // TODO: Should we set truncate?
1239 msg := fmt.Sprintf("out-of-space. Cannot fit attribute %v into GetNextResponse message",
1240 attrDef.GetName())
1241 return nil, me.NewMessageTruncatedError(msg)
1242 }
1243 }
1244 }
1245 }
1246 return meLayer, nil
1247}
1248
1249func TestResultFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1250 mask, err := checkAttributeMask(m, opt.attributeMask)
1251 if err != nil {
1252 return nil, err
1253 }
1254 // Common for all MEs
1255 meLayer := &TestResultMsg{
1256 MeBasePacket: MeBasePacket{
1257 EntityClass: m.GetClassID(),
1258 EntityInstance: m.GetEntityID(),
1259 },
1260 }
1261 // Get payload space available
1262 maxPayload := maxPacketAvailable(m, opt)
1263
1264 // TODO: Lots of work to do
1265
1266 fmt.Println(mask, maxPayload)
1267 return meLayer, errors.New("todo: Not implemented")
1268}
1269
1270func GetCurrentDataRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1271 mask, err := checkAttributeMask(m, opt.attributeMask)
1272 if err != nil {
1273 return nil, err
1274 }
1275 // Common for all MEs
1276 meLayer := &GetCurrentDataRequest{
1277 MeBasePacket: MeBasePacket{
1278 EntityClass: m.GetClassID(),
1279 EntityInstance: m.GetEntityID(),
1280 },
1281 }
1282 // Get payload space available
1283 maxPayload := maxPacketAvailable(m, opt)
1284
1285 // TODO: Lots of work to do
1286
1287 fmt.Println(mask, maxPayload)
1288 return meLayer, errors.New("todo: Not implemented")
1289}
1290
1291func GetCurrentDataResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1292 mask, err := checkAttributeMask(m, opt.attributeMask)
1293 if err != nil {
1294 return nil, err
1295 }
1296 // Common for all MEs
1297 meLayer := &GetCurrentDataResponse{
1298 MeBasePacket: MeBasePacket{
1299 EntityClass: m.GetClassID(),
1300 EntityInstance: m.GetEntityID(),
1301 },
1302 }
1303 // Get payload space available
1304 maxPayload := maxPacketAvailable(m, opt)
1305
1306 // TODO: Lots of work to do
1307
1308 fmt.Println(mask, maxPayload)
1309 return meLayer, errors.New("todo: Not implemented")
1310}
1311
1312func SetTableRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1313 if opt.frameFormat != ExtendedIdent {
1314 return nil, errors.New("SetTable message type only supported with Extended OMCI Messaging")
1315 }
1316 mask, err := checkAttributeMask(m, opt.attributeMask)
1317 if err != nil {
1318 return nil, err
1319 }
1320 // Common for all MEs
1321 meLayer := &SetTableRequest{
1322 MeBasePacket: MeBasePacket{
1323 EntityClass: m.GetClassID(),
1324 EntityInstance: m.GetEntityID(),
1325 },
1326 }
1327 // Get payload space available
1328 maxPayload := maxPacketAvailable(m, opt)
1329
1330 // TODO: Lots of work to do
1331
1332 fmt.Println(mask, maxPayload)
1333 return meLayer, errors.New("todo: Not implemented")
1334}
1335
1336func SetTableResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
1337 if opt.frameFormat != ExtendedIdent {
1338 return nil, errors.New("SetTable message type only supported with Extended OMCI Messaging")
1339 }
1340 mask, err := checkAttributeMask(m, opt.attributeMask)
1341 if err != nil {
1342 return nil, err
1343 }
1344 // Common for all MEs
1345 meLayer := &SetTableResponse{
1346 MeBasePacket: MeBasePacket{
1347 EntityClass: m.GetClassID(),
1348 EntityInstance: m.GetEntityID(),
1349 },
1350 }
1351 // Get payload space available
1352 maxPayload := maxPacketAvailable(m, opt)
1353
1354 // TODO: Lots of work to do
1355
1356 fmt.Println(mask, maxPayload)
1357 return meLayer, errors.New("todo: Not implemented")
1358}