blob: 6d2220041b4a6e3868861d757a853540a2e8e7fb [file] [log] [blame]
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package omci
18
19import (
Matteo Scandolof9d43412021-01-12 11:11:34 -080020 "errors"
Matteo Scandolo9a1842d2021-02-08 16:00:17 -080021 "fmt"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070022 "github.com/google/gopacket"
Matteo Scandolof9d43412021-01-12 11:11:34 -080023 "github.com/opencord/omci-lib-go"
24 me "github.com/opencord/omci-lib-go/generated"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070025 log "github.com/sirupsen/logrus"
Matteo Scandolo9a1842d2021-02-08 16:00:17 -080026 "strconv"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070027)
28
29var omciLogger = log.WithFields(log.Fields{
30 "module": "OMCI",
31})
32
Matteo Scandolo9a1842d2021-02-08 16:00:17 -080033// we have a fixed number of 8 T-CONTS
34var reportedTcontsMeId = []uint16{
35 32769,
36 32770,
37 32771,
38 32772,
39 32773,
40 32774,
41 32775,
42 32776,
Matteo Scandolo40e067f2019-10-16 16:59:41 -070043}
44
Matteo Scandolof9d43412021-01-12 11:11:34 -080045// NOTE this is basically the same as https://github.com/opencord/voltha-openonu-adapter-go/blob/master/internal/pkg/onuadaptercore/omci_cc.go#L545-L564
46// we should probably move it in "omci-lib-go"
Matteo Scandolo992a23e2021-02-04 15:35:04 -080047func Serialize(msgType omci.MessageType, request gopacket.SerializableLayer, tid uint16) ([]byte, error) {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070048 omciLayer := &omci.OMCI{
49 TransactionID: tid,
50 MessageType: msgType,
51 }
52 var options gopacket.SerializeOptions
53 options.FixLengths = true
54
55 buffer := gopacket.NewSerializeBuffer()
56 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
57 if err != nil {
58 return nil, err
59 }
60 return buffer.Bytes(), nil
61}
62
Matteo Scandolo40e067f2019-10-16 16:59:41 -070063func CreateMibResetRequest(tid uint16) ([]byte, error) {
64
65 request := &omci.MibResetRequest{
66 MeBasePacket: omci.MeBasePacket{
Matteo Scandolof9d43412021-01-12 11:11:34 -080067 EntityClass: me.OnuDataClassID,
Matteo Scandolo40e067f2019-10-16 16:59:41 -070068 },
69 }
Matteo Scandolo992a23e2021-02-04 15:35:04 -080070 pkt, err := Serialize(omci.MibResetRequestType, request, tid)
Matteo Scandolo40e067f2019-10-16 16:59:41 -070071 if err != nil {
72 omciLogger.WithFields(log.Fields{
73 "Err": err,
Matteo Scandolo992a23e2021-02-04 15:35:04 -080074 }).Fatalf("Cannot Serialize MibResetRequest")
Matteo Scandolo40e067f2019-10-16 16:59:41 -070075 return nil, err
76 }
Matteo Scandolo992a23e2021-02-04 15:35:04 -080077 return HexEncode(pkt)
Matteo Scandolo40e067f2019-10-16 16:59:41 -070078}
79
Matteo Scandolof9d43412021-01-12 11:11:34 -080080func CreateMibResetResponse(tid uint16) ([]byte, error) {
81
Matteo Scandolof9d43412021-01-12 11:11:34 -080082 request := &omci.MibResetResponse{
83 MeBasePacket: omci.MeBasePacket{
84 EntityClass: me.OnuDataClassID,
85 },
86 Result: me.Success,
87 }
Matteo Scandolo992a23e2021-02-04 15:35:04 -080088 pkt, err := Serialize(omci.MibResetResponseType, request, tid)
Matteo Scandolof9d43412021-01-12 11:11:34 -080089 if err != nil {
90 omciLogger.WithFields(log.Fields{
91 "Err": err,
Matteo Scandolo992a23e2021-02-04 15:35:04 -080092 }).Error("Cannot Serialize MibResetResponse")
Matteo Scandolof9d43412021-01-12 11:11:34 -080093 return nil, err
94 }
95 return pkt, nil
96}
97
Matteo Scandolo40e067f2019-10-16 16:59:41 -070098func CreateMibUploadRequest(tid uint16) ([]byte, error) {
99 request := &omci.MibUploadRequest{
100 MeBasePacket: omci.MeBasePacket{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800101 EntityClass: me.OnuDataClassID,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700102 // Default Instance ID is 0
103 },
104 }
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800105 pkt, err := Serialize(omci.MibUploadRequestType, request, tid)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700106 if err != nil {
107 omciLogger.WithFields(log.Fields{
108 "Err": err,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800109 }).Fatalf("Cannot Serialize MibUploadRequest")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700110 return nil, err
111 }
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800112 return HexEncode(pkt)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700113}
114
Matteo Scandolof9d43412021-01-12 11:11:34 -0800115func CreateMibUploadResponse(tid uint16) ([]byte, error) {
116
117 numberOfCommands := uint16(291) //NOTE should this be configurable? (not until we have moved all the messages away from omci-sim)
118
119 request := &omci.MibUploadResponse{
120 MeBasePacket: omci.MeBasePacket{
121 EntityClass: me.OnuDataClassID,
122 },
123 NumberOfCommands: numberOfCommands,
124 }
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800125 pkt, err := Serialize(omci.MibUploadResponseType, request, tid)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800126 if err != nil {
127 omciLogger.WithFields(log.Fields{
128 "Err": err,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800129 }).Error("Cannot Serialize MibUploadResponse")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800130 return nil, err
131 }
132 return pkt, nil
133}
134
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700135func CreateMibUploadNextRequest(tid uint16, seqNumber uint16) ([]byte, error) {
136
137 request := &omci.MibUploadNextRequest{
138 MeBasePacket: omci.MeBasePacket{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800139 EntityClass: me.OnuDataClassID,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700140 // Default Instance ID is 0
141 },
142 CommandSequenceNumber: seqNumber,
143 }
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800144 pkt, err := Serialize(omci.MibUploadNextRequestType, request, tid)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700145
146 if err != nil {
147 omciLogger.WithFields(log.Fields{
148 "Err": err,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800149 }).Fatalf("Cannot Serialize MibUploadNextRequest")
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700150 return nil, err
151 }
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800152 return HexEncode(pkt)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700153}
154
Matteo Scandolof9d43412021-01-12 11:11:34 -0800155func ParseMibUploadNextRequest(omciPkt gopacket.Packet) (*omci.MibUploadNextRequest, error) {
156 msgLayer := omciPkt.Layer(omci.LayerTypeMibUploadNextRequest)
157 if msgLayer == nil {
158 err := "omci Msg layer could not be detected for LayerTypeMibUploadNextRequest"
159 omciLogger.Error(err)
160 return nil, errors.New(err)
Scott Bakerb90c4312020-03-12 21:33:25 -0700161 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800162 msgObj, msgOk := msgLayer.(*omci.MibUploadNextRequest)
163 if !msgOk {
164 err := "omci Msg layer could not be assigned for MibUploadNextRequest"
165 omciLogger.Error(err)
166 return nil, errors.New(err)
167 }
168 return msgObj, nil
Scott Bakerb90c4312020-03-12 21:33:25 -0700169}
170
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800171func CreateMibUploadNextResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, mds uint8) ([]byte, error) {
Scott Bakerb90c4312020-03-12 21:33:25 -0700172
Matteo Scandolof9d43412021-01-12 11:11:34 -0800173 msgObj, err := ParseMibUploadNextRequest(omciPkt)
Scott Bakerb90c4312020-03-12 21:33:25 -0700174 if err != nil {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800175 err := "omci Msg layer could not be assigned for LayerTypeGetRequest"
176 omciLogger.Error(err)
177 return nil, errors.New(err)
Scott Bakerb90c4312020-03-12 21:33:25 -0700178 }
179
Matteo Scandolof9d43412021-01-12 11:11:34 -0800180 omciLogger.WithFields(log.Fields{
181 "EntityClass": msgObj.EntityClass,
182 "EntityInstance": msgObj.EntityInstance,
183 "CommandSequenceNumber": msgObj.CommandSequenceNumber,
184 }).Trace("received-omci-mibUploadNext-request")
Scott Bakerb90c4312020-03-12 21:33:25 -0700185
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800186 var reportedMe *me.ManagedEntity
Matteo Scandolof9d43412021-01-12 11:11:34 -0800187 var meErr me.OmciErrors
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800188
Matteo Scandolof9d43412021-01-12 11:11:34 -0800189 switch msgObj.CommandSequenceNumber {
190 case 0:
191 reportedMe, meErr = me.NewOnuData(me.ParamData{Attributes: me.AttributeValueMap{
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800192 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800193 }})
194 if meErr.GetError() != nil {
195 omciLogger.Errorf("NewOnuData %v", meErr.Error())
196 }
Scott Bakerb90c4312020-03-12 21:33:25 -0700197
Matteo Scandolof9d43412021-01-12 11:11:34 -0800198 case 1:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800199 reportedMe, meErr = me.NewCircuitPack(me.ParamData{
200 EntityID: 257, // first UNI
201 Attributes: me.AttributeValueMap{
202 "Type": 47,
203 "NumberOfPorts": 4,
204 "SerialNumber": toOctets("BBSM-Circuit-Pack", 20),
205 "Version": toOctets("v0.0.1", 20),
206 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800207 if meErr.GetError() != nil {
208 omciLogger.Errorf("NewCircuitPack %v", meErr.Error())
209 }
210 case 2:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800211 reportedMe, meErr = me.NewCircuitPack(me.ParamData{
212 EntityID: 257, // first UNI
213 Attributes: me.AttributeValueMap{
214 "VendorId": "ONF",
215 "AdministrativeState": 0,
216 "OperationalState": 0,
217 "BridgedOrIpInd": 0,
218 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800219 if meErr.GetError() != nil {
220 omciLogger.Errorf("NewCircuitPack %v", meErr.Error())
221 }
222 case 3:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800223 reportedMe, meErr = me.NewCircuitPack(me.ParamData{
224 EntityID: 257, // first UNI
225 Attributes: me.AttributeValueMap{
226 "EquipmentId": toOctets("BBSM-Circuit-Pack", 20),
227 "CardConfiguration": 0,
228 "TotalTContBufferNumber": 8,
229 "TotalPriorityQueueNumber": 8,
230 "TotalTrafficSchedulerNumber": 16,
231 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800232 if meErr.GetError() != nil {
233 omciLogger.Errorf("NewCircuitPack %v", meErr.Error())
234 }
235 case 4:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800236 reportedMe, meErr = me.NewCircuitPack(me.ParamData{
237 EntityID: 257, // first UNI
238 Attributes: me.AttributeValueMap{
239 "PowerShedOverride": uint32(0),
240 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800241 if meErr.GetError() != nil {
242 omciLogger.Errorf("NewCircuitPack %v", meErr.Error())
243 }
244 case 5:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800245 reportedMe, meErr = me.NewCircuitPack(me.ParamData{
246 EntityID: 257,
247 Attributes: me.AttributeValueMap{
248 "Type": 238,
249 "NumberOfPorts": 4, //number of UNI for this device
250 "SerialNumber": toOctets("BBSM-Circuit-Pack-2", 20),
251 "Version": toOctets("v0.0.1", 20),
252 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800253 if meErr.GetError() != nil {
254 omciLogger.Errorf("NewCircuitPack %v", meErr.Error())
255 }
256 case 6:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800257 reportedMe, meErr = me.NewCircuitPack(me.ParamData{
258 EntityID: 257, // first UNI
259 Attributes: me.AttributeValueMap{
260 "VendorId": "ONF",
261 "AdministrativeState": 0,
262 "OperationalState": 0,
263 "BridgedOrIpInd": 0,
264 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800265 if meErr.GetError() != nil {
266 omciLogger.Errorf("NewCircuitPack %v", meErr.Error())
267 }
268 case 7:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800269 reportedMe, meErr = me.NewCircuitPack(me.ParamData{
270 EntityID: 257, // first UNI
271 Attributes: me.AttributeValueMap{
272 "EquipmentId": toOctets("BBSM-Circuit-Pack", 20),
273 "CardConfiguration": 0,
274 "TotalTContBufferNumber": 0,
275 "TotalPriorityQueueNumber": 8,
276 "TotalTrafficSchedulerNumber": 0,
277 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800278 if meErr.GetError() != nil {
279 omciLogger.Errorf("NewCircuitPack %v", meErr.Error())
280 }
281 case 8:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800282 reportedMe, meErr = me.NewCircuitPack(me.ParamData{
283 EntityID: 257, // first UNI
284 Attributes: me.AttributeValueMap{
285 "PowerShedOverride": uint32(0),
286 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800287 if meErr.GetError() != nil {
288 omciLogger.Errorf("NewCircuitPack %v", meErr.Error())
289 }
290 case 9, 10, 11, 12:
291 // NOTE we're reporting for different UNIs, the IDs are 257, 258, 259, 260
292 meInstance := 248 + msgObj.CommandSequenceNumber
293 reportedMe, meErr = me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
294 EntityID: meInstance,
295 Attributes: me.AttributeValueMap{
296 "ExpectedType": 0,
297 "SensedType": 47,
298 "AutoDetectionConfiguration": 0,
299 "EthernetLoopbackConfiguration": 0,
300 "AdministrativeState": 0,
301 "OperationalState": 0,
302 "ConfigurationInd": 3,
303 "MaxFrameSize": 1518,
304 "DteOrDceInd": 0,
305 "PauseTime": 0,
306 "BridgedOrIpInd": 2,
307 "Arc": 0,
308 "ArcInterval": 0,
309 "PppoeFilter": 0,
310 "PowerControl": 0,
311 }})
312 if meErr.GetError() != nil {
313 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
314 }
315 case 13, 14, 15, 16, 17, 18, 19, 20:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800316 reportedMe, meErr = me.NewTCont(me.ParamData{
317 // NOTE fetch the correct T-CONT MeID based on the sequence number
318 EntityID: reportedTcontsMeId[msgObj.CommandSequenceNumber-13],
319 Attributes: me.AttributeValueMap{
320 "AllocId": 65535,
321 },
322 })
Matteo Scandolof9d43412021-01-12 11:11:34 -0800323 if meErr.GetError() != nil {
324 omciLogger.Errorf("NewTCont %v", meErr.Error())
325 }
326 case 21:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800327 reportedMe, meErr = me.NewAniG(me.ParamData{
328 EntityID: 32769, // same as the first T-CONT
329 Attributes: me.AttributeValueMap{
330 "Arc": 0,
331 "ArcInterval": 0,
332 "Deprecated": 0,
333 "GemBlockLength": 48,
334 "LowerOpticalThreshold": 255,
335 "LowerTransmitPowerThreshold": 129,
336 "OnuResponseTime": 0,
337 "OpticalSignalLevel": 57428,
338 "PiggybackDbaReporting": 0,
339 "SignalDegradeThreshold": 9,
340 "SignalFailThreshold": 5,
341 "SrIndication": 1,
342 "TotalTcontNumber": 8,
343 "TransmitOpticalLevel": 3171,
344 "UpperOpticalThreshold": 255,
345 "UpperTransmitPowerThreshold": 129,
346 },
347 })
Matteo Scandolof9d43412021-01-12 11:11:34 -0800348 if meErr.GetError() != nil {
349 omciLogger.Errorf("NewAniG %v", meErr.Error())
350 }
351 case 22, 23, 24, 25:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800352 // NOTE we're reporting for different UNIs, the IDs are 257, 258, 259, 260
353 meInstance := 235 + msgObj.CommandSequenceNumber
354 reportedMe, meErr = me.NewUniG(me.ParamData{
355 EntityID: meInstance,
356 Attributes: me.AttributeValueMap{
357 "AdministrativeState": 0,
358 "Deprecated": 0,
359 "ManagementCapability": 0,
360 "NonOmciManagementIdentifier": 0,
361 "RelayAgentOptions": 0,
362 }})
Matteo Scandolof9d43412021-01-12 11:11:34 -0800363 if meErr.GetError() != nil {
364 omciLogger.Errorf("NewUniG %v", meErr.Error())
365 }
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800366 // Prior-Q with mask downstream
Matteo Scandolof9d43412021-01-12 11:11:34 -0800367 case 26, 30, 34, 38, 42, 46, 50, 54,
368 58, 62, 66, 70, 74, 78, 82, 86,
369 90, 94, 98, 102, 106, 110, 114, 118,
370 122, 126, 130, 134, 138, 142, 146, 150,
371 154, 158, 162, 166, 170, 174, 178, 182,
372 186, 190, 194, 198, 202, 206, 210, 214,
373 218, 222, 226, 230, 234, 238, 242, 246,
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800374 250, 254, 258, 262, 266, 270, 274, 278,
375 // Prior-Q with attribute list downstream
376 27, 31, 35, 39, 43, 47, 51, 55,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800377 59, 63, 67, 71, 75, 79, 83, 87,
378 91, 95, 99, 103, 107, 111, 115, 119,
379 123, 127, 131, 135, 139, 143, 147, 151,
380 155, 159, 163, 167, 171, 175, 179, 183,
381 187, 191, 195, 199, 203, 207, 211, 215,
382 219, 223, 227, 231, 235, 239, 243, 247,
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800383 251, 255, 259, 263, 267, 271, 275, 279,
384 // Prior-Q with mask upstream
385 28, 32, 36, 40, 44, 48, 52, 56,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800386 60, 64, 68, 72, 76, 80, 84, 88,
387 92, 96, 100, 104, 108, 112, 116, 120,
388 124, 128, 132, 136, 140, 144, 148, 152,
389 156, 160, 164, 168, 172, 176, 180, 184,
390 188, 192, 196, 200, 204, 208, 212, 216,
391 220, 224, 228, 232, 236, 240, 244, 248,
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800392 252, 256, 260, 264, 268, 272, 276, 280,
393 // Prior-Q with attribute list upstream
394 29, 33, 37, 41, 45, 49, 53, 57,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800395 61, 65, 69, 73, 77, 81, 85, 89,
396 93, 97, 101, 105, 109, 113, 117, 121,
397 125, 129, 133, 137, 141, 145, 149, 153,
398 157, 161, 165, 169, 173, 177, 181, 185,
399 189, 193, 197, 201, 205, 209, 213, 217,
400 221, 225, 229, 233, 237, 241, 245, 249,
401 253, 257, 261, 265, 269, 273, 277, 281:
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800402
403 reportedMe, meErr = GeneratePriorityQueueMe(msgObj.CommandSequenceNumber)
404
Matteo Scandolof9d43412021-01-12 11:11:34 -0800405 if meErr.GetError() != nil {
406 omciLogger.Errorf("NewPriorityQueue %v", meErr.Error())
407 }
408 case 282, 283, 284, 285, 286, 287, 288, 289:
409 reportedMe, meErr = me.NewTrafficScheduler(me.ParamData{Attributes: me.AttributeValueMap{
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800410 "TContPointer": 32768, // NOTE does this need to change?
Matteo Scandolof9d43412021-01-12 11:11:34 -0800411 "TrafficSchedulerPointer": 0,
412 "Policy": 02,
413 "PriorityWeight": 0,
414 }})
415 if meErr.GetError() != nil {
416 omciLogger.Errorf("NewTrafficScheduler %v", meErr.Error())
417 }
418 case 290:
419 reportedMe, meErr = me.NewOnu2G(me.ParamData{Attributes: me.AttributeValueMap{
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800420 "ConnectivityCapability": 127,
421 "CurrentConnectivityMode": 0,
422 "Deprecated": 1,
423 "PriorityQueueScaleFactor": 1,
424 "QualityOfServiceQosConfigurationFlexibility": 63,
425 "Sysuptime": 0,
426 "TotalGemPortIdNumber": 8,
427 "TotalPriorityQueueNumber": 64,
428 "TotalTrafficSchedulerNumber": 8,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800429 }})
430 if meErr.GetError() != nil {
431 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
432 }
433 default:
434 omciLogger.Warn("unsupported-CommandSequenceNumber-in-mib-upload-next", msgObj.CommandSequenceNumber)
435 return nil, nil
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700436 }
437
Matteo Scandolof9d43412021-01-12 11:11:34 -0800438 response := &omci.MibUploadNextResponse{
439 MeBasePacket: omci.MeBasePacket{
440 EntityClass: me.OnuDataClassID,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700441 },
Matteo Scandolof9d43412021-01-12 11:11:34 -0800442 ReportedME: *reportedMe,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700443 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700444
Matteo Scandolof9d43412021-01-12 11:11:34 -0800445 omciLogger.WithFields(log.Fields{
446 "reportedMe": reportedMe,
447 }).Trace("created-omci-mibUploadNext-response")
448
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800449 pkt, err := Serialize(omci.MibUploadNextResponseType, response, omciMsg.TransactionID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800450
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700451 if err != nil {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800452 omciLogger.WithFields(log.Fields{
453 "Err": err,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800454 }).Fatalf("Cannot Serialize MibUploadNextRequest")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800455 return nil, err
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700456 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700457
Matteo Scandolof9d43412021-01-12 11:11:34 -0800458 return pkt, nil
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700459}
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800460
461func GeneratePriorityQueueMe(sequence uint16) (*me.ManagedEntity, me.OmciErrors) {
462
463 iteration := sequence - 26
464
465 // we report 256 messages for priority queues,
466 // 128 downstream and 128 upstream
467 // we repeat 64 times the quartet:
468 // - downstream with mask
469 // - downstream with attributes (same MeID as the previous)
470 // - upstream with mask
471 // - upstream with attributes (same MeID as the previous)
472
473 // very ugly way to define whether the priority queue is upstream or downstream
474 // (first 2 blocks are downstream, second two are upstream)
475 // for example sequence 26, 27 are downstream
476 // sequence 28, 29 are upstream
477 isDownstream := ((sequence-26)%4 == 0) || ((sequence-27)%4 == 0)
478 // entityIds are:
479 // - 1 to 64 for downstream (hex 0001 to 0040)
480 // - 32769 to 32832 for upstream (hex 8001 to 8040)
481 var entityId uint16
482 if isDownstream {
483 entityId = (iteration)/4 + 1
484 } else {
485 entityId = (iteration)/4 + 32769
486 }
487
488 var relatedPort uint32
489 if isDownstream {
490 // downstream the related port is:
491 // - Circuit Pack/ UNI port of UNI Port (01 01/04)
492 // - priority 0 to 15 -> iteration%16
493
494 // every 16 iteration (of 4 commands) we move to the next the TCONT MeID
495 uniPort := int(iteration/64) + 1
496 priority := (iteration / 4) % 16
497
498 // concat the uniPort and priority in an hex string
499 // we have a single circuit pack, so we hardcode it
500 v := fmt.Sprintf("010%x000%x", uniPort, priority)
501
502 // convert back to int
503 k, _ := strconv.ParseInt(v, 16, 64)
504 relatedPort = uint32(k)
505 } else {
506 // upstream the related port is:
507 // - Tcont MeID -> reportedTcontsMeId[ceil(iteration/4/8)]
508 // - priority 0 to 7 -> iteration%8
509
510 // every 8 iteration (of 4 commands) we move to the next the TCONT MeID
511 tcontMe := reportedTcontsMeId[int(iteration/32)]
512 priority := (iteration / 4) % 8
513
514 // concat the tcontMe and priority in an hex string
515 v := fmt.Sprintf("%x000%x", tcontMe, priority)
516
517 // convert back to int
518 k, _ := strconv.ParseInt(v, 16, 64)
519 relatedPort = uint32(k)
520 }
521
522 return me.NewPriorityQueue(me.ParamData{
523 EntityID: entityId,
524 Attributes: me.AttributeValueMap{
525 "QueueConfigurationOption": 0,
526 "MaximumQueueSize": 100,
527 "AllocatedQueueSize": 100,
528 "DiscardBlockCounterResetInterval": 0,
529 "ThresholdValueForDiscardedBlocksDueToBufferOverflow": 0,
530 "RelatedPort": relatedPort,
531 "TrafficSchedulerPointer": 264,
532 "Weight": 1,
533 "BackPressureOperation": 1,
534 "BackPressureTime": 0,
535 "BackPressureOccurQueueThreshold": 0,
536 "BackPressureClearQueueThreshold": 0,
537 },
538 })
539}