blob: 81eb2ceef9fde997c6e58d1c788192455732403f [file] [log] [blame]
Chip Boling610117d2021-09-09 11:24:34 -05001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
3 * Copyright 2020-present Open Networking Foundation
4
5 * 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
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package meframe
19
20import (
21 "errors"
22 "github.com/google/gopacket"
Andrea Campanellae0cd8232021-10-15 15:10:23 +020023 . "github.com/opencord/omci-lib-go/v2"
24 me "github.com/opencord/omci-lib-go/v2/generated"
Chip Boling610117d2021-09-09 11:24:34 -050025)
26
27func MibUploadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
28 if opt.frameFormat == ExtendedIdent {
29 return nil, errors.New("extended message set for this message type is not supported")
30 }
31 // Common for all MEs
32 meLayer := &MibUploadRequest{
33 MeBasePacket: MeBasePacket{
34 EntityClass: m.GetClassID(),
35 EntityInstance: 0,
36 Extended: opt.frameFormat == ExtendedIdent,
37 },
38 }
39 return meLayer, nil
40}
41
42func MibUploadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
43 if opt.frameFormat == ExtendedIdent {
44 return nil, errors.New("extended message set for this message type is not supported")
45 }
46 // Common for all MEs
47 meLayer := &MibUploadResponse{
48 MeBasePacket: MeBasePacket{
49 EntityClass: m.GetClassID(),
50 EntityInstance: 0,
51 Extended: opt.frameFormat == ExtendedIdent,
52 },
53 NumberOfCommands: opt.sequenceNumberCountOrSize,
54 }
55 return meLayer, nil
56}
57
58func MibUploadNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
59 if opt.frameFormat == ExtendedIdent {
60 return nil, errors.New("extended message set for this message type is not supported")
61 }
62 // Common for all MEs
63 meLayer := &MibUploadNextRequest{
64 MeBasePacket: MeBasePacket{
65 EntityClass: m.GetClassID(),
66 EntityInstance: 0,
67 Extended: opt.frameFormat == ExtendedIdent,
68 },
69 CommandSequenceNumber: opt.sequenceNumberCountOrSize,
70 }
71 return meLayer, nil
72}
73
74func MibUploadNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
75 if opt.frameFormat == ExtendedIdent {
76 return nil, errors.New("extended message set for this message type is not supported")
77 }
78 // Common for all MEs
79 meLayer := &MibUploadNextResponse{
80 MeBasePacket: MeBasePacket{
81 EntityClass: m.GetClassID(),
82 EntityInstance: m.GetEntityID(),
83 Extended: opt.frameFormat == ExtendedIdent,
84 },
85 }
86 if opt.payload == nil {
87 // Shortcut used to specify the request sequence number is out of range, encode
88 // a ME instance with class ID of zero to specify this per ITU G.988
89 meDef := me.ManagedEntityDefinition{
90 Name: "InvalidSequenceNumberManagedEntity",
91 ClassID: me.ClassID(0),
92 MessageTypes: nil,
93 AttributeDefinitions: make(me.AttributeDefinitionMap),
94 }
95 opt.payload, _ = me.NewManagedEntity(meDef)
96 }
97 if _, ok := opt.payload.(*[]me.ManagedEntity); ok {
98 if opt.frameFormat == BaselineIdent {
99 return nil, errors.New("invalid payload for Baseline message")
100 }
101 // TODO: List of MEs. valid for extended messages only
102 } else if managedEntity, ok := opt.payload.(*me.ManagedEntity); ok {
103 // Single ME
104 meLayer.ReportedME = *managedEntity
105 } else {
106 return nil, errors.New("invalid payload for MibUploadNextResponse frame")
107 }
108 return meLayer, nil
109}