blob: dc40f5356158824b3d60e2cdc1d3707a916a46c3 [file] [log] [blame]
Matteo Scandolof9d43412021-01-12 11:11:34 -08001/*
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 (
20 "encoding/hex"
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"
Matteo Scandolo5863f002021-02-08 08:08:14 -080026 "github.com/opencord/voltha-protos/v4/go/openolt"
Matteo Scandolof9d43412021-01-12 11:11:34 -080027 log "github.com/sirupsen/logrus"
Girish Gowdraa539f522021-02-15 23:00:45 -080028 "math/rand"
Matteo Scandolof9d43412021-01-12 11:11:34 -080029 "strconv"
30)
31
32func ParseGetRequest(omciPkt gopacket.Packet) (*omci.GetRequest, error) {
33 msgLayer := omciPkt.Layer(omci.LayerTypeGetRequest)
34 if msgLayer == nil {
35 err := "omci Msg layer could not be detected for LayerTypeGetRequest"
36 omciLogger.Error(err)
37 return nil, errors.New(err)
38 }
39 msgObj, msgOk := msgLayer.(*omci.GetRequest)
40 if !msgOk {
41 err := "omci Msg layer could not be assigned for LayerTypeGetRequest"
42 omciLogger.Error(err)
43 return nil, errors.New(err)
44 }
45 return msgObj, nil
46}
47
Matteo Scandolo992a23e2021-02-04 15:35:04 -080048func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8) ([]byte, error) {
Matteo Scandolof9d43412021-01-12 11:11:34 -080049
50 msgObj, err := ParseGetRequest(omciPkt)
51
52 if err != nil {
53 return nil, err
54 }
55
56 omciLogger.WithFields(log.Fields{
57 "EntityClass": msgObj.EntityClass,
58 "EntityInstance": msgObj.EntityInstance,
59 "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask),
Matteo Scandolo992a23e2021-02-04 15:35:04 -080060 }).Trace("received-omci-get-request")
Matteo Scandolof9d43412021-01-12 11:11:34 -080061
62 var response *omci.GetResponse
63 switch msgObj.EntityClass {
64 case me.Onu2GClassID:
65 response = createOnu2gResponse(msgObj.AttributeMask, msgObj.EntityInstance)
66 case me.OnuGClassID:
Matteo Scandolo5863f002021-02-08 08:08:14 -080067 response = createOnugResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuSn)
Matteo Scandolof9d43412021-01-12 11:11:34 -080068 case me.SoftwareImageClassID:
69 response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance)
70 case me.IpHostConfigDataClassID:
71 response = createIpHostResponse(msgObj.AttributeMask, msgObj.EntityInstance)
72 case me.UniGClassID:
73 response = createUnigResponse(msgObj.AttributeMask, msgObj.EntityInstance)
74 case me.PhysicalPathTerminationPointEthernetUniClassID:
75 response = createPptpResponse(msgObj.AttributeMask, msgObj.EntityInstance)
76 case me.AniGClassID:
77 response = createAnigResponse(msgObj.AttributeMask, msgObj.EntityInstance)
78 case me.OnuDataClassID:
Matteo Scandolo992a23e2021-02-04 15:35:04 -080079 response = createOnuDataResponse(msgObj.AttributeMask, msgObj.EntityInstance, mds)
Girish Gowdraa539f522021-02-15 23:00:45 -080080 case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID:
81 response = createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance)
82 case me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID:
83 response = createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance)
84 case me.EthernetPerformanceMonitoringHistoryDataClassID:
85 response = createEthernetPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
Girish Gowdra6d9a1a42021-03-05 16:07:15 -080086 case me.FecPerformanceMonitoringHistoryDataClassID:
87 response = createFecPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
88 case me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID:
89 response = createGemPortNetworkCtpPerformanceMonitoringHistoryData(msgObj.AttributeMask, msgObj.EntityInstance)
Matteo Scandolof9d43412021-01-12 11:11:34 -080090 default:
91 omciLogger.WithFields(log.Fields{
92 "EntityClass": msgObj.EntityClass,
93 "EntityInstance": msgObj.EntityInstance,
94 "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask),
95 }).Warnf("do-not-know-how-to-handle-get-request-for-me-class")
96 return nil, nil
97 }
98
Matteo Scandolo992a23e2021-02-04 15:35:04 -080099 pkt, err := Serialize(omci.GetResponseType, response, omciMsg.TransactionID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800100 if err != nil {
101 omciLogger.WithFields(log.Fields{
102 "Err": err,
103 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800104 }).Error("cannot-Serialize-Onu2gResponse")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800105 return nil, err
106 }
107
108 log.WithFields(log.Fields{
109 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
110 "pkt": hex.EncodeToString(pkt),
111 }).Trace("omci-get-response")
112
113 return pkt, nil
114}
115
116func createOnu2gResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
117
118 managedEntity, meErr := me.NewOnu2G(me.ParamData{
119 EntityID: entityID,
120 Attributes: me.AttributeValueMap{
121 "ManagedEntityId": entityID,
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800122 "EquipmentId": toOctets("12345123451234512345", 20),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800123 "OpticalNetworkUnitManagementAndControlChannelOmccVersion": 180,
124 "VendorProductCode": 0,
125 "SecurityCapability": 1,
126 "SecurityMode": 1,
127 "TotalPriorityQueueNumber": 1,
128 "TotalTrafficSchedulerNumber": 1,
129 "Deprecated": 1,
130 "TotalGemPortIdNumber": 32,
131 "Sysuptime": 319389947, // NOTE need to be smarter?
132 "ConnectivityCapability": 127,
133 "CurrentConnectivityMode": 5,
134 "QualityOfServiceQosConfigurationFlexibility": 48,
135 "PriorityQueueScaleFactor": 1,
136 },
137 })
138
139 if meErr.GetError() != nil {
140 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
141 return nil
142 }
143
144 return &omci.GetResponse{
145 MeBasePacket: omci.MeBasePacket{
146 EntityClass: me.Onu2GClassID,
147 },
148 Attributes: managedEntity.GetAttributeValueMap(),
149 AttributeMask: attributeMask,
150 Result: me.Success,
151 }
152}
153
Matteo Scandolo5863f002021-02-08 08:08:14 -0800154func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse {
155
156 managedEntity, meErr := me.NewOnuG(me.ParamData{
157 EntityID: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800158 Attributes: me.AttributeValueMap{
159 "ManagedEntityId": entityID,
160 "VendorId": toOctets("BBSM", 4),
161 "Version": toOctets("v0.0.1", 14),
Matteo Scandolo5863f002021-02-08 08:08:14 -0800162 "SerialNumber": append(onuSn.VendorId, onuSn.VendorSpecific...),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800163 "TrafficManagementOption": 0,
164 "Deprecated": 0,
165 "BatteryBackup": 0,
166 "AdministrativeState": 0,
167 "OperationalState": 0,
168 "OnuSurvivalTime": 10,
169 "LogicalOnuId": toOctets("BBSM", 24),
170 "LogicalPassword": toOctets("BBSM", 12),
171 "CredentialsStatus": 0,
172 "ExtendedTcLayerOptions": 0,
173 },
Matteo Scandolo5863f002021-02-08 08:08:14 -0800174 })
175
176 if meErr.GetError() != nil {
177 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
178 return nil
Matteo Scandolof9d43412021-01-12 11:11:34 -0800179 }
Matteo Scandolo5863f002021-02-08 08:08:14 -0800180
181 return &omci.GetResponse{
182 MeBasePacket: omci.MeBasePacket{
183 EntityClass: me.OnuGClassID,
184 },
185 Attributes: managedEntity.GetAttributeValueMap(),
186 AttributeMask: attributeMask,
187 Result: me.Success,
188 }
189
190 //return &omci.GetResponse{
191 // MeBasePacket: omci.MeBasePacket{
192 // EntityClass: me.OnuGClassID,
193 // EntityInstance: entityID,
194 // },
195 // Attributes: me.AttributeValueMap{
196 //
197 // },
198 // Result: me.Success,
199 // AttributeMask: attributeMask,
200 //}
Matteo Scandolof9d43412021-01-12 11:11:34 -0800201}
202
203func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
204 // NOTE that we need send the response for the correct ME Instance or the adapter won't process it
205 return &omci.GetResponse{
206 MeBasePacket: omci.MeBasePacket{
207 EntityClass: me.SoftwareImageClassID,
208 EntityInstance: entityInstance,
209 },
210 Attributes: me.AttributeValueMap{
211 "ManagedEntityId": 0,
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800212 "Version": toOctets("00000000000001", 14),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800213 "IsCommitted": 1,
214 "IsActive": 1,
215 "IsValid": 1,
216 "ProductCode": toOctets("product-code", 25),
217 "ImageHash": toOctets("broadband-sim", 16),
218 },
219 Result: me.Success,
220 AttributeMask: attributeMask,
221 }
222}
223
224func createIpHostResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
225 return &omci.GetResponse{
226 MeBasePacket: omci.MeBasePacket{
227 EntityClass: me.IpHostConfigDataClassID,
228 EntityInstance: entityInstance,
229 },
230 Attributes: me.AttributeValueMap{
231 "ManagedEntityId": 0,
232 "MacAddress": toOctets("aabbcc", 6),
233 },
234 Result: me.Success,
235 AttributeMask: attributeMask,
236 }
237}
238
239func createUnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
240 managedEntity, meErr := me.NewUniG(me.ParamData{
241 EntityID: entityID,
242 Attributes: me.AttributeValueMap{
243 "ManagedEntityId": entityID,
244 "Deprecated": 0,
245 "AdministrativeState": 0,
246 "ManagementCapability": 0,
247 "NonOmciManagementIdentifier": 1,
248 "RelayAgentOptions": 1,
249 },
250 })
251
252 if meErr.GetError() != nil {
253 omciLogger.Errorf("NewUniG %v", meErr.Error())
254 return nil
255 }
256
257 return &omci.GetResponse{
258 MeBasePacket: omci.MeBasePacket{
259 EntityClass: me.UniGClassID,
260 },
261 Attributes: managedEntity.GetAttributeValueMap(),
262 AttributeMask: attributeMask,
263 Result: me.Success,
264 }
265}
266
267func createPptpResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
268 managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
269 EntityID: entityID,
270 Attributes: me.AttributeValueMap{
271 "ManagedEntityId": entityID,
272 "ExpectedType": 0,
273 "SensedType": 0,
274 "AutoDetectionConfiguration": 0,
275 "EthernetLoopbackConfiguration": 0,
276 "AdministrativeState": 0,
277 "OperationalState": 0,
278 "ConfigurationInd": 0,
279 "MaxFrameSize": 0,
280 "DteOrDceInd": 0,
281 "PauseTime": 0,
282 "BridgedOrIpInd": 0,
283 "Arc": 0,
284 "ArcInterval": 0,
285 "PppoeFilter": 0,
286 "PowerControl": 0,
287 },
288 })
289
290 if meErr.GetError() != nil {
291 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
292 return nil
293 }
294
295 return &omci.GetResponse{
296 MeBasePacket: omci.MeBasePacket{
297 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
298 },
299 Attributes: managedEntity.GetAttributeValueMap(),
300 AttributeMask: attributeMask,
301 Result: me.Success,
302 }
303}
304
Girish Gowdraa539f522021-02-15 23:00:45 -0800305func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800306 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800307 EntityID: entityID,
308 Attributes: me.AttributeValueMap{
Girish Gowdraa539f522021-02-15 23:00:45 -0800309 "ManagedEntityId": entityID,
310 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
311 "ThresholdData12Id": 0,
312 "DropEvents": rand.Intn(100),
313 "Octets": rand.Intn(100),
314 "Packets": rand.Intn(100),
315 "BroadcastPackets": rand.Intn(100),
316 "MulticastPackets": rand.Intn(100),
317 "CrcErroredPackets": rand.Intn(100),
318 "UndersizePackets": rand.Intn(100),
319 "OversizePackets": rand.Intn(100),
320 "Packets64Octets": rand.Intn(100),
321 "Packets65To127Octets": rand.Intn(100),
322 "Packets128To255Octets": rand.Intn(100),
323 "Packets256To511Octets": rand.Intn(100),
324 "Packets512To1023Octets": rand.Intn(100),
325 "Packets1024To1518Octets": rand.Intn(100),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800326 },
327 })
328
329 if meErr.GetError() != nil {
Girish Gowdraa539f522021-02-15 23:00:45 -0800330 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error())
Matteo Scandolof9d43412021-01-12 11:11:34 -0800331 return nil
332 }
333
Girish Gowdraa539f522021-02-15 23:00:45 -0800334 // L2 PM counters MEs exceed max allowed OMCI payload size.
335 // So the request/responses are always multipart.
336 // First identify the attributes that are not requested in the current GET request.
337 // Then filter out those attributes from the responses in the current GET response.
338 unwantedAttributeMask := ^attributeMask
339 var i uint16
340 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
341 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
342 if (1<<(16-i))&unwantedAttributeMask > 0 {
343 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
344 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
345 }
346 }
347 }
348
Matteo Scandolof9d43412021-01-12 11:11:34 -0800349 return &omci.GetResponse{
350 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800351 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID,
352 EntityInstance: entityID,
353 },
354 Attributes: managedEntity.GetAttributeValueMap(),
355 AttributeMask: attributeMask,
356 Result: me.Success,
357 }
358}
359
360func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800361 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{
362 EntityID: entityID,
363 Attributes: me.AttributeValueMap{
364 "ManagedEntityId": entityID,
365 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
366 "ThresholdData12Id": 0,
367 "DropEvents": rand.Intn(100),
368 "Octets": rand.Intn(100),
369 "Packets": rand.Intn(100),
370 "BroadcastPackets": rand.Intn(100),
371 "MulticastPackets": rand.Intn(100),
372 "CrcErroredPackets": rand.Intn(100),
373 "UndersizePackets": rand.Intn(100),
374 "OversizePackets": rand.Intn(100),
375 "Packets64Octets": rand.Intn(100),
376 "Packets65To127Octets": rand.Intn(100),
377 "Packets128To255Octets": rand.Intn(100),
378 "Packets256To511Octets": rand.Intn(100),
379 "Packets512To1023Octets": rand.Intn(100),
380 "Packets1024To1518Octets": rand.Intn(100),
381 },
382 })
383
384 if meErr.GetError() != nil {
385 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error())
386 return nil
387 }
388
389 // L2 PM counters MEs exceed max allowed OMCI payload size.
390 // So the request/responses are always multipart.
391 // First identify the attributes that are not requested in the current GET request.
392 // Then filter out those attributes from the responses in the current GET response.
393 unwantedAttributeMask := ^attributeMask
394 var i uint16
395 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
396 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
397 if (1<<(16-i))&unwantedAttributeMask > 0 {
398 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
399 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
400 }
401 }
402 }
403
404 return &omci.GetResponse{
405 MeBasePacket: omci.MeBasePacket{
406 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID,
407 EntityInstance: entityID,
408 },
409 Attributes: managedEntity.GetAttributeValueMap(),
410 AttributeMask: attributeMask,
411 Result: me.Success,
412 }
413}
414
415func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800416 managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{
417 EntityID: entityID,
418 Attributes: me.AttributeValueMap{
419 "ManagedEntityId": entityID,
420 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
421 "ThresholdData12Id": 0,
422 "FcsErrors": rand.Intn(100),
423 "ExcessiveCollisionCounter": rand.Intn(100),
424 "LateCollisionCounter": rand.Intn(100),
425 "FramesTooLong": rand.Intn(100),
426 "BufferOverflowsOnReceive": rand.Intn(100),
427 "BufferOverflowsOnTransmit": rand.Intn(100),
428 "SingleCollisionFrameCounter": rand.Intn(100),
429 "MultipleCollisionsFrameCounter": rand.Intn(100),
430 "SqeCounter": rand.Intn(100),
431 "DeferredTransmissionCounter": rand.Intn(100),
432 "InternalMacTransmitErrorCounter": rand.Intn(100),
433 "CarrierSenseErrorCounter": rand.Intn(100),
434 "AlignmentErrorCounter": rand.Intn(100),
435 "InternalMacReceiveErrorCounter": rand.Intn(100),
436 },
437 })
438
439 if meErr.GetError() != nil {
440 omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error())
441 return nil
442 }
443
444 // L2 PM counters MEs exceed max allowed OMCI payload size.
445 // So the request/responses are always multipart.
446 // First identify the attributes that are not requested in the current GET request.
447 // Then filter out those attributes from the responses in the current GET response.
448 unwantedAttributeMask := ^attributeMask
449 var i uint16
450 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
451 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
452 if (1<<(16-i))&unwantedAttributeMask > 0 {
453 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
454 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
455 }
456 }
457 }
458
459 return &omci.GetResponse{
460 MeBasePacket: omci.MeBasePacket{
461 EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID,
462 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800463 },
464 Attributes: managedEntity.GetAttributeValueMap(),
465 AttributeMask: attributeMask,
466 Result: me.Success,
467 }
468}
469
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800470func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
471 managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{
472 EntityID: entityID,
473 Attributes: me.AttributeValueMap{
474 "ManagedEntityId": entityID,
475 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
476 "ThresholdData12Id": 0,
477 "CorrectedBytes": rand.Intn(100),
478 "CorrectedCodeWords": rand.Intn(100),
479 "UncorrectableCodeWords": rand.Intn(100),
480 "TotalCodeWords": rand.Intn(100),
481 "FecSeconds": rand.Intn(100),
482 },
483 })
484
485 if meErr.GetError() != nil {
486 omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error())
487 return nil
488 }
489
490 // FEC History counter fits within single gem payload.
491 // No need of the logical we use in other Ethernet History counters or Gem Port History counters
492
493 return &omci.GetResponse{
494 MeBasePacket: omci.MeBasePacket{
495 EntityClass: me.FecPerformanceMonitoringHistoryDataClassID,
496 EntityInstance: entityID,
497 },
498 Attributes: managedEntity.GetAttributeValueMap(),
499 AttributeMask: attributeMask,
500 Result: me.Success,
501 }
502}
503
504func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse {
505 managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{
506 EntityID: entityID,
507 Attributes: me.AttributeValueMap{
508 "ManagedEntityId": entityID,
509 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
510 "ThresholdData12Id": 0,
511 "TransmittedGemFrames": rand.Intn(100),
512 "ReceivedGemFrames": rand.Intn(100),
513 "ReceivedPayloadBytes": rand.Intn(100),
514 "TransmittedPayloadBytes": rand.Intn(100),
515 "EncryptionKeyErrors": rand.Intn(100),
516 },
517 })
518
519 if meErr.GetError() != nil {
520 omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error())
521 return nil
522 }
523
524 // L2 PM counters MEs exceed max allowed OMCI payload size.
525 // So the request/responses are always multipart.
526 // First identify the attributes that are not requested in the current GET request.
527 // Then filter out those attributes from the responses in the current GET response.
528 unwantedAttributeMask := ^attributeMask
529 var i uint16
530 for i = 1; i <= 7; i++ { // 1 and 7 because they are allowed valid min and max index keys in AttributeValueMap.
531 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
532 if (1<<(7-i))&unwantedAttributeMask > 0 {
533 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
534 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
535 }
536 }
537 }
538
539 return &omci.GetResponse{
540 MeBasePacket: omci.MeBasePacket{
541 EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID,
542 EntityInstance: entityID,
543 },
544 Attributes: managedEntity.GetAttributeValueMap(),
545 AttributeMask: attributeMask,
546 Result: me.Success,
547 }
548}
549
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800550func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800551 managedEntity, meErr := me.NewOnuData(me.ParamData{
552 EntityID: entityID,
553 Attributes: me.AttributeValueMap{
554 "ManagedEntityId": entityID,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800555 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800556 },
557 })
558
559 if meErr.GetError() != nil {
560 omciLogger.Errorf("NewOnuData %v", meErr.Error())
561 return nil
562 }
563
564 return &omci.GetResponse{
565 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800566 EntityClass: me.OnuDataClassID,
567 EntityInstance: entityID,
568 },
569 Attributes: managedEntity.GetAttributeValueMap(),
570 AttributeMask: attributeMask,
571 Result: me.Success,
572 }
573}
574
575func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
576 managedEntity, meErr := me.NewAniG(me.ParamData{
577 EntityID: entityID,
578 Attributes: me.AttributeValueMap{
579 "ManagedEntityId": entityID,
580 "SrIndication": 0,
581 "TotalTcontNumber": 0,
582 "GemBlockLength": 0,
583 "PiggybackDbaReporting": 0,
584 "Deprecated": 0,
585 "SignalFailThreshold": 0,
586 "SignalDegradeThreshold": 0,
587 "Arc": 0,
588 "ArcInterval": 0,
589 "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
590 "LowerOpticalThreshold": 0,
591 "UpperOpticalThreshold": 0,
592 "OnuResponseTime": 0,
593 "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
594 "LowerTransmitPowerThreshold": 0,
595 "UpperTransmitPowerThreshold": 0,
596 },
597 })
598
599 if meErr.GetError() != nil {
600 omciLogger.Errorf("NewAniG %v", meErr.Error())
601 return nil
602 }
603
604 return &omci.GetResponse{
605 MeBasePacket: omci.MeBasePacket{
606 EntityClass: me.AniGClassID,
607 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800608 },
609 Attributes: managedEntity.GetAttributeValueMap(),
610 AttributeMask: attributeMask,
611 Result: me.Success,
612 }
613}
614
615func toOctets(str string, size int) []byte {
616 asciiBytes := []byte(str)
617
618 if len(asciiBytes) < size {
619 missing := size - len(asciiBytes)
620 for i := 0; i < missing; i++ {
621 asciiBytes = append(asciiBytes, []byte{0x00}[0])
622 }
623 }
624 return asciiBytes
625}