blob: 6d6d3fb987fe1cd05883ebcff5f38583924301b5 [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 "fmt"
23 "github.com/google/gopacket"
24 . "github.com/opencord/omci-lib-go"
25 me "github.com/opencord/omci-lib-go/generated"
26)
27
28func StartSoftwareDownloadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
29 if opt.frameFormat == ExtendedIdent {
30 return nil, errors.New("extended message set for this message type is not supported")
31 }
32 // Common for all MEs
33 meLayer := &StartSoftwareDownloadRequest{
34 MeBasePacket: MeBasePacket{
35 EntityClass: m.GetClassID(),
36 EntityInstance: m.GetEntityID(),
37 Extended: opt.frameFormat == ExtendedIdent,
38 },
39 WindowSize: opt.software.WindowSize,
40 ImageSize: opt.software.ImageSize,
41 NumberOfCircuitPacks: byte(len(opt.software.CircuitPacks)),
42 CircuitPacks: opt.software.CircuitPacks,
43 }
44 // TODO: Add length check to insure we do not exceed maximum packet size
45 // payloadAvailable := int(maxPacketAvailable(m, opt))
46 payloadAvailable := 2
47 sizeNeeded := 1
48 if sizeNeeded > payloadAvailable {
49 // TODO: Should we set truncate?
50 msg := "out-of-space. Cannot fit Circuit Pack instances into Start Software Download Request message"
51 return nil, me.NewMessageTruncatedError(msg)
52 }
53 return meLayer, nil
54}
55
56func StartSoftwareDownloadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
57 if opt.frameFormat == ExtendedIdent {
58 return nil, errors.New("extended message set for this message type is not supported")
59 }
60 // Common for all MEs
61 meLayer := &StartSoftwareDownloadResponse{
62 MeBasePacket: MeBasePacket{
63 EntityClass: m.GetClassID(),
64 EntityInstance: m.GetEntityID(),
65 Extended: opt.frameFormat == ExtendedIdent,
66 },
67 WindowSize: opt.software.WindowSize,
68 NumberOfInstances: byte(len(opt.software.CircuitPacks)),
69 MeResults: opt.software.Results,
70 }
71 // TODO: Add length check to insure we do not exceed maximum packet size
72 // payloadAvailable := int(maxPacketAvailable(m, opt))
73 payloadAvailable := 2
74 sizeNeeded := 1
75 if sizeNeeded > payloadAvailable {
76 // TODO: Should we set truncate?
77 msg := "out-of-space. Cannot fit Results into Start Software Download Response message"
78 return nil, me.NewMessageTruncatedError(msg)
79 }
80 return meLayer, nil
81}
82
83func DownloadSectionRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
84 if opt.software.Data == nil {
85 return nil, me.NewNonStatusError("Software image data missing")
86 }
87 // Common for all MEs
88 meLayer := &DownloadSectionRequest{
89 MeBasePacket: MeBasePacket{
90 EntityClass: m.GetClassID(),
91 EntityInstance: m.GetEntityID(),
92 Extended: opt.frameFormat == ExtendedIdent,
93 },
94 SectionNumber: opt.software.SectionNumber,
95 SectionData: opt.software.Data,
96 }
97 return meLayer, nil
98}
99
100func DownloadSectionResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
101 // Common for all MEs
102 meLayer := &DownloadSectionResponse{
103 MeBasePacket: MeBasePacket{
104 EntityClass: m.GetClassID(),
105 EntityInstance: m.GetEntityID(),
106 Extended: opt.frameFormat == ExtendedIdent,
107 },
108 Result: opt.result,
109 SectionNumber: opt.software.SectionNumber,
110 }
111 return meLayer, nil
112}
113
114func EndSoftwareDownloadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
115 if opt.frameFormat == ExtendedIdent {
116 return nil, errors.New("extended message set for this message type is not supported")
117 }
118 mask, err := checkAttributeMask(m, opt.attributeMask)
119 if err != nil {
120 return nil, err
121 }
122 // Common for all MEs
123 meLayer := &EndSoftwareDownloadRequest{
124 MeBasePacket: MeBasePacket{
125 EntityClass: m.GetClassID(),
126 EntityInstance: m.GetEntityID(),
127 Extended: opt.frameFormat == ExtendedIdent,
128 },
129 }
130 // Get payload space available
131 maxPayload := maxPacketAvailable(m, opt)
132
133 // TODO: Lots of work to do
134
135 fmt.Println(mask, maxPayload)
136 return meLayer, errors.New("todo: Not implemented")
137}
138
139func EndSoftwareDownloadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
140 if opt.frameFormat == ExtendedIdent {
141 return nil, errors.New("extended message set for this message type is not supported")
142 }
143 mask, err := checkAttributeMask(m, opt.attributeMask)
144 if err != nil {
145 return nil, err
146 }
147 // Common for all MEs
148 meLayer := &EndSoftwareDownloadResponse{
149 MeBasePacket: MeBasePacket{
150 EntityClass: m.GetClassID(),
151 EntityInstance: m.GetEntityID(),
152 Extended: opt.frameFormat == ExtendedIdent,
153 },
154 }
155 // Get payload space available
156 maxPayload := maxPacketAvailable(m, opt)
157
158 // TODO: Lots of work to do
159
160 fmt.Println(mask, maxPayload)
161 return meLayer, errors.New("todo: Not implemented")
162}
163
164func ActivateSoftwareRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
165 if opt.frameFormat == ExtendedIdent {
166 return nil, errors.New("extended message set for this message type is not supported")
167 }
168 mask, err := checkAttributeMask(m, opt.attributeMask)
169 if err != nil {
170 return nil, err
171 }
172 // Common for all MEs
173 meLayer := &ActivateSoftwareRequest{
174 MeBasePacket: MeBasePacket{
175 EntityClass: m.GetClassID(),
176 EntityInstance: m.GetEntityID(),
177 Extended: opt.frameFormat == ExtendedIdent,
178 },
179 }
180 // Get payload space available
181 maxPayload := maxPacketAvailable(m, opt)
182
183 // TODO: Lots of work to do
184
185 fmt.Println(mask, maxPayload)
186 return meLayer, errors.New("todo: Not implemented")
187}
188
189func ActivateSoftwareResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
190 if opt.frameFormat == ExtendedIdent {
191 return nil, errors.New("extended message set for this message type is not supported")
192 }
193 mask, err := checkAttributeMask(m, opt.attributeMask)
194 if err != nil {
195 return nil, err
196 }
197 // Common for all MEs
198 meLayer := &ActivateSoftwareResponse{
199 MeBasePacket: MeBasePacket{
200 EntityClass: m.GetClassID(),
201 EntityInstance: m.GetEntityID(),
202 Extended: opt.frameFormat == ExtendedIdent,
203 },
204 }
205 // Get payload space available
206 maxPayload := maxPacketAvailable(m, opt)
207
208 // TODO: Lots of work to do
209
210 fmt.Println(mask, maxPayload)
211 return meLayer, errors.New("todo: Not implemented")
212}
213
214func CommitSoftwareRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
215 if opt.frameFormat == ExtendedIdent {
216 return nil, errors.New("extended message set for this message type is not supported")
217 }
218 mask, err := checkAttributeMask(m, opt.attributeMask)
219 if err != nil {
220 return nil, err
221 }
222 // Common for all MEs
223 meLayer := &CommitSoftwareRequest{
224 MeBasePacket: MeBasePacket{
225 EntityClass: m.GetClassID(),
226 EntityInstance: m.GetEntityID(),
227 Extended: opt.frameFormat == ExtendedIdent,
228 },
229 }
230 // Get payload space available
231 maxPayload := maxPacketAvailable(m, opt)
232
233 // TODO: Lots of work to do
234
235 fmt.Println(mask, maxPayload)
236 return meLayer, errors.New("todo: Not implemented")
237}
238
239func CommitSoftwareResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
240 if opt.frameFormat == ExtendedIdent {
241 return nil, errors.New("extended message set for this message type is not supported")
242 }
243 mask, err := checkAttributeMask(m, opt.attributeMask)
244 if err != nil {
245 return nil, err
246 }
247 // Common for all MEs
248 meLayer := &CommitSoftwareResponse{
249 MeBasePacket: MeBasePacket{
250 EntityClass: m.GetClassID(),
251 EntityInstance: m.GetEntityID(),
252 Extended: opt.frameFormat == ExtendedIdent,
253 },
254 }
255 // Get payload space available
256 maxPayload := maxPacketAvailable(m, opt)
257
258 // TODO: Lots of work to do
259
260 fmt.Println(mask, maxPayload)
261 return meLayer, errors.New("todo: Not implemented")
262}