blob: e47dc0ce8f80613df678913d92c2d4d6194c2ecc [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{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800259 EntityClass: me.UniGClassID,
260 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800261 },
262 Attributes: managedEntity.GetAttributeValueMap(),
263 AttributeMask: attributeMask,
264 Result: me.Success,
265 }
266}
267
268func createPptpResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
269 managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
270 EntityID: entityID,
271 Attributes: me.AttributeValueMap{
272 "ManagedEntityId": entityID,
273 "ExpectedType": 0,
274 "SensedType": 0,
275 "AutoDetectionConfiguration": 0,
276 "EthernetLoopbackConfiguration": 0,
277 "AdministrativeState": 0,
278 "OperationalState": 0,
279 "ConfigurationInd": 0,
280 "MaxFrameSize": 0,
281 "DteOrDceInd": 0,
282 "PauseTime": 0,
283 "BridgedOrIpInd": 0,
284 "Arc": 0,
285 "ArcInterval": 0,
286 "PppoeFilter": 0,
287 "PowerControl": 0,
288 },
289 })
290
291 if meErr.GetError() != nil {
292 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
293 return nil
294 }
295
296 return &omci.GetResponse{
297 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800298 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
299 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800300 },
301 Attributes: managedEntity.GetAttributeValueMap(),
302 AttributeMask: attributeMask,
303 Result: me.Success,
304 }
305}
306
Girish Gowdraa539f522021-02-15 23:00:45 -0800307func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800308 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800309 EntityID: entityID,
310 Attributes: me.AttributeValueMap{
Girish Gowdraa539f522021-02-15 23:00:45 -0800311 "ManagedEntityId": entityID,
312 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
313 "ThresholdData12Id": 0,
314 "DropEvents": rand.Intn(100),
315 "Octets": rand.Intn(100),
316 "Packets": rand.Intn(100),
317 "BroadcastPackets": rand.Intn(100),
318 "MulticastPackets": rand.Intn(100),
319 "CrcErroredPackets": rand.Intn(100),
320 "UndersizePackets": rand.Intn(100),
321 "OversizePackets": rand.Intn(100),
322 "Packets64Octets": rand.Intn(100),
323 "Packets65To127Octets": rand.Intn(100),
324 "Packets128To255Octets": rand.Intn(100),
325 "Packets256To511Octets": rand.Intn(100),
326 "Packets512To1023Octets": rand.Intn(100),
327 "Packets1024To1518Octets": rand.Intn(100),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800328 },
329 })
330
331 if meErr.GetError() != nil {
Girish Gowdraa539f522021-02-15 23:00:45 -0800332 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error())
Matteo Scandolof9d43412021-01-12 11:11:34 -0800333 return nil
334 }
335
Girish Gowdraa539f522021-02-15 23:00:45 -0800336 // L2 PM counters MEs exceed max allowed OMCI payload size.
337 // So the request/responses are always multipart.
338 // First identify the attributes that are not requested in the current GET request.
339 // Then filter out those attributes from the responses in the current GET response.
340 unwantedAttributeMask := ^attributeMask
341 var i uint16
342 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
343 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
344 if (1<<(16-i))&unwantedAttributeMask > 0 {
345 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
346 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
347 }
348 }
349 }
350
Matteo Scandolof9d43412021-01-12 11:11:34 -0800351 return &omci.GetResponse{
352 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800353 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID,
354 EntityInstance: entityID,
355 },
356 Attributes: managedEntity.GetAttributeValueMap(),
357 AttributeMask: attributeMask,
358 Result: me.Success,
359 }
360}
361
362func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800363 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{
364 EntityID: entityID,
365 Attributes: me.AttributeValueMap{
366 "ManagedEntityId": entityID,
367 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
368 "ThresholdData12Id": 0,
369 "DropEvents": rand.Intn(100),
370 "Octets": rand.Intn(100),
371 "Packets": rand.Intn(100),
372 "BroadcastPackets": rand.Intn(100),
373 "MulticastPackets": rand.Intn(100),
374 "CrcErroredPackets": rand.Intn(100),
375 "UndersizePackets": rand.Intn(100),
376 "OversizePackets": rand.Intn(100),
377 "Packets64Octets": rand.Intn(100),
378 "Packets65To127Octets": rand.Intn(100),
379 "Packets128To255Octets": rand.Intn(100),
380 "Packets256To511Octets": rand.Intn(100),
381 "Packets512To1023Octets": rand.Intn(100),
382 "Packets1024To1518Octets": rand.Intn(100),
383 },
384 })
385
386 if meErr.GetError() != nil {
387 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error())
388 return nil
389 }
390
391 // L2 PM counters MEs exceed max allowed OMCI payload size.
392 // So the request/responses are always multipart.
393 // First identify the attributes that are not requested in the current GET request.
394 // Then filter out those attributes from the responses in the current GET response.
395 unwantedAttributeMask := ^attributeMask
396 var i uint16
397 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
398 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
399 if (1<<(16-i))&unwantedAttributeMask > 0 {
400 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
401 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
402 }
403 }
404 }
405
406 return &omci.GetResponse{
407 MeBasePacket: omci.MeBasePacket{
408 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID,
409 EntityInstance: entityID,
410 },
411 Attributes: managedEntity.GetAttributeValueMap(),
412 AttributeMask: attributeMask,
413 Result: me.Success,
414 }
415}
416
417func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800418 managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{
419 EntityID: entityID,
420 Attributes: me.AttributeValueMap{
421 "ManagedEntityId": entityID,
422 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
423 "ThresholdData12Id": 0,
424 "FcsErrors": rand.Intn(100),
425 "ExcessiveCollisionCounter": rand.Intn(100),
426 "LateCollisionCounter": rand.Intn(100),
427 "FramesTooLong": rand.Intn(100),
428 "BufferOverflowsOnReceive": rand.Intn(100),
429 "BufferOverflowsOnTransmit": rand.Intn(100),
430 "SingleCollisionFrameCounter": rand.Intn(100),
431 "MultipleCollisionsFrameCounter": rand.Intn(100),
432 "SqeCounter": rand.Intn(100),
433 "DeferredTransmissionCounter": rand.Intn(100),
434 "InternalMacTransmitErrorCounter": rand.Intn(100),
435 "CarrierSenseErrorCounter": rand.Intn(100),
436 "AlignmentErrorCounter": rand.Intn(100),
437 "InternalMacReceiveErrorCounter": rand.Intn(100),
438 },
439 })
440
441 if meErr.GetError() != nil {
442 omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error())
443 return nil
444 }
445
446 // L2 PM counters MEs exceed max allowed OMCI payload size.
447 // So the request/responses are always multipart.
448 // First identify the attributes that are not requested in the current GET request.
449 // Then filter out those attributes from the responses in the current GET response.
450 unwantedAttributeMask := ^attributeMask
451 var i uint16
452 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
453 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
454 if (1<<(16-i))&unwantedAttributeMask > 0 {
455 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
456 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
457 }
458 }
459 }
460
461 return &omci.GetResponse{
462 MeBasePacket: omci.MeBasePacket{
463 EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID,
464 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800465 },
466 Attributes: managedEntity.GetAttributeValueMap(),
467 AttributeMask: attributeMask,
468 Result: me.Success,
469 }
470}
471
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800472func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
473 managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{
474 EntityID: entityID,
475 Attributes: me.AttributeValueMap{
476 "ManagedEntityId": entityID,
477 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
478 "ThresholdData12Id": 0,
479 "CorrectedBytes": rand.Intn(100),
480 "CorrectedCodeWords": rand.Intn(100),
481 "UncorrectableCodeWords": rand.Intn(100),
482 "TotalCodeWords": rand.Intn(100),
483 "FecSeconds": rand.Intn(100),
484 },
485 })
486
487 if meErr.GetError() != nil {
488 omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error())
489 return nil
490 }
491
492 // FEC History counter fits within single gem payload.
493 // No need of the logical we use in other Ethernet History counters or Gem Port History counters
494
495 return &omci.GetResponse{
496 MeBasePacket: omci.MeBasePacket{
497 EntityClass: me.FecPerformanceMonitoringHistoryDataClassID,
498 EntityInstance: entityID,
499 },
500 Attributes: managedEntity.GetAttributeValueMap(),
501 AttributeMask: attributeMask,
502 Result: me.Success,
503 }
504}
505
506func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse {
507 managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{
508 EntityID: entityID,
509 Attributes: me.AttributeValueMap{
510 "ManagedEntityId": entityID,
511 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
512 "ThresholdData12Id": 0,
513 "TransmittedGemFrames": rand.Intn(100),
514 "ReceivedGemFrames": rand.Intn(100),
515 "ReceivedPayloadBytes": rand.Intn(100),
516 "TransmittedPayloadBytes": rand.Intn(100),
517 "EncryptionKeyErrors": rand.Intn(100),
518 },
519 })
520
521 if meErr.GetError() != nil {
522 omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error())
523 return nil
524 }
525
526 // L2 PM counters MEs exceed max allowed OMCI payload size.
527 // So the request/responses are always multipart.
528 // First identify the attributes that are not requested in the current GET request.
529 // Then filter out those attributes from the responses in the current GET response.
530 unwantedAttributeMask := ^attributeMask
531 var i uint16
532 for i = 1; i <= 7; i++ { // 1 and 7 because they are allowed valid min and max index keys in AttributeValueMap.
533 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
534 if (1<<(7-i))&unwantedAttributeMask > 0 {
535 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
536 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
537 }
538 }
539 }
540
541 return &omci.GetResponse{
542 MeBasePacket: omci.MeBasePacket{
543 EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID,
544 EntityInstance: entityID,
545 },
546 Attributes: managedEntity.GetAttributeValueMap(),
547 AttributeMask: attributeMask,
548 Result: me.Success,
549 }
550}
551
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800552func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800553 managedEntity, meErr := me.NewOnuData(me.ParamData{
554 EntityID: entityID,
555 Attributes: me.AttributeValueMap{
556 "ManagedEntityId": entityID,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800557 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800558 },
559 })
560
561 if meErr.GetError() != nil {
562 omciLogger.Errorf("NewOnuData %v", meErr.Error())
563 return nil
564 }
565
566 return &omci.GetResponse{
567 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800568 EntityClass: me.OnuDataClassID,
569 EntityInstance: entityID,
570 },
571 Attributes: managedEntity.GetAttributeValueMap(),
572 AttributeMask: attributeMask,
573 Result: me.Success,
574 }
575}
576
577func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
578 managedEntity, meErr := me.NewAniG(me.ParamData{
579 EntityID: entityID,
580 Attributes: me.AttributeValueMap{
581 "ManagedEntityId": entityID,
582 "SrIndication": 0,
583 "TotalTcontNumber": 0,
584 "GemBlockLength": 0,
585 "PiggybackDbaReporting": 0,
586 "Deprecated": 0,
587 "SignalFailThreshold": 0,
588 "SignalDegradeThreshold": 0,
589 "Arc": 0,
590 "ArcInterval": 0,
591 "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
592 "LowerOpticalThreshold": 0,
593 "UpperOpticalThreshold": 0,
594 "OnuResponseTime": 0,
595 "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
596 "LowerTransmitPowerThreshold": 0,
597 "UpperTransmitPowerThreshold": 0,
598 },
599 })
600
601 if meErr.GetError() != nil {
602 omciLogger.Errorf("NewAniG %v", meErr.Error())
603 return nil
604 }
605
606 return &omci.GetResponse{
607 MeBasePacket: omci.MeBasePacket{
608 EntityClass: me.AniGClassID,
609 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800610 },
611 Attributes: managedEntity.GetAttributeValueMap(),
612 AttributeMask: attributeMask,
613 Result: me.Success,
614 }
615}
616
617func toOctets(str string, size int) []byte {
618 asciiBytes := []byte(str)
619
620 if len(asciiBytes) < size {
621 missing := size - len(asciiBytes)
622 for i := 0; i < missing; i++ {
623 asciiBytes = append(asciiBytes, []byte{0x00}[0])
624 }
625 }
626 return asciiBytes
627}