blob: 5172f603e81069fc37e5c1393da70fed26867071 [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 Scandolocedde462021-03-09 17:37:16 -080048func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8, activeImageEntityId uint16, committedImageEntityId uint16) ([]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:
Matteo Scandolocedde462021-03-09 17:37:16 -080069 response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance, activeImageEntityId, committedImageEntityId)
Matteo Scandolof9d43412021-01-12 11:11:34 -080070 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
Matteo Scandolocedde462021-03-09 17:37:16 -0800203func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16, activeImageEntityId uint16, committedImageEntityId uint16) *omci.GetResponse {
204
205 omciLogger.WithFields(log.Fields{
206 "EntityInstance": entityInstance,
207 }).Info("received-get-software-image-request")
208
209 // Only one image can be active and committed
210 committed := 0
211 active := 0
212 if entityInstance == activeImageEntityId {
213 active = 1
214 }
215 if entityInstance == committedImageEntityId {
216 committed = 1
217 }
218
Matteo Scandolof9d43412021-01-12 11:11:34 -0800219 // NOTE that we need send the response for the correct ME Instance or the adapter won't process it
Matteo Scandolocedde462021-03-09 17:37:16 -0800220 res := &omci.GetResponse{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800221 MeBasePacket: omci.MeBasePacket{
222 EntityClass: me.SoftwareImageClassID,
223 EntityInstance: entityInstance,
224 },
225 Attributes: me.AttributeValueMap{
226 "ManagedEntityId": 0,
Matteo Scandolo9a1842d2021-02-08 16:00:17 -0800227 "Version": toOctets("00000000000001", 14),
Matteo Scandolocedde462021-03-09 17:37:16 -0800228 "IsCommitted": committed,
229 "IsActive": active,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800230 "IsValid": 1,
231 "ProductCode": toOctets("product-code", 25),
232 "ImageHash": toOctets("broadband-sim", 16),
233 },
234 Result: me.Success,
235 AttributeMask: attributeMask,
236 }
Matteo Scandolocedde462021-03-09 17:37:16 -0800237
238 omciLogger.WithFields(log.Fields{
239 "omciMessage": res,
240 "entityId": entityInstance,
241 "active": active,
242 "committed": committed,
243 }).Info("Reporting SoftwareImage")
244
245 return res
Matteo Scandolof9d43412021-01-12 11:11:34 -0800246}
247
248func createIpHostResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
249 return &omci.GetResponse{
250 MeBasePacket: omci.MeBasePacket{
251 EntityClass: me.IpHostConfigDataClassID,
252 EntityInstance: entityInstance,
253 },
254 Attributes: me.AttributeValueMap{
255 "ManagedEntityId": 0,
256 "MacAddress": toOctets("aabbcc", 6),
257 },
258 Result: me.Success,
259 AttributeMask: attributeMask,
260 }
261}
262
263func createUnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
264 managedEntity, meErr := me.NewUniG(me.ParamData{
265 EntityID: entityID,
266 Attributes: me.AttributeValueMap{
267 "ManagedEntityId": entityID,
268 "Deprecated": 0,
269 "AdministrativeState": 0,
270 "ManagementCapability": 0,
271 "NonOmciManagementIdentifier": 1,
272 "RelayAgentOptions": 1,
273 },
274 })
275
276 if meErr.GetError() != nil {
277 omciLogger.Errorf("NewUniG %v", meErr.Error())
278 return nil
279 }
280
281 return &omci.GetResponse{
282 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800283 EntityClass: me.UniGClassID,
284 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800285 },
286 Attributes: managedEntity.GetAttributeValueMap(),
287 AttributeMask: attributeMask,
288 Result: me.Success,
289 }
290}
291
292func createPptpResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
293 managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
294 EntityID: entityID,
295 Attributes: me.AttributeValueMap{
296 "ManagedEntityId": entityID,
297 "ExpectedType": 0,
298 "SensedType": 0,
299 "AutoDetectionConfiguration": 0,
300 "EthernetLoopbackConfiguration": 0,
301 "AdministrativeState": 0,
302 "OperationalState": 0,
303 "ConfigurationInd": 0,
304 "MaxFrameSize": 0,
305 "DteOrDceInd": 0,
306 "PauseTime": 0,
307 "BridgedOrIpInd": 0,
308 "Arc": 0,
309 "ArcInterval": 0,
310 "PppoeFilter": 0,
311 "PowerControl": 0,
312 },
313 })
314
315 if meErr.GetError() != nil {
316 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
317 return nil
318 }
319
320 return &omci.GetResponse{
321 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800322 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
323 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800324 },
325 Attributes: managedEntity.GetAttributeValueMap(),
326 AttributeMask: attributeMask,
327 Result: me.Success,
328 }
329}
330
Girish Gowdraa539f522021-02-15 23:00:45 -0800331func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800332 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800333 EntityID: entityID,
334 Attributes: me.AttributeValueMap{
Girish Gowdraa539f522021-02-15 23:00:45 -0800335 "ManagedEntityId": entityID,
336 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
337 "ThresholdData12Id": 0,
338 "DropEvents": rand.Intn(100),
339 "Octets": rand.Intn(100),
340 "Packets": rand.Intn(100),
341 "BroadcastPackets": rand.Intn(100),
342 "MulticastPackets": rand.Intn(100),
343 "CrcErroredPackets": rand.Intn(100),
344 "UndersizePackets": rand.Intn(100),
345 "OversizePackets": rand.Intn(100),
346 "Packets64Octets": rand.Intn(100),
347 "Packets65To127Octets": rand.Intn(100),
348 "Packets128To255Octets": rand.Intn(100),
349 "Packets256To511Octets": rand.Intn(100),
350 "Packets512To1023Octets": rand.Intn(100),
351 "Packets1024To1518Octets": rand.Intn(100),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800352 },
353 })
354
355 if meErr.GetError() != nil {
Girish Gowdraa539f522021-02-15 23:00:45 -0800356 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error())
Matteo Scandolof9d43412021-01-12 11:11:34 -0800357 return nil
358 }
359
Girish Gowdraa539f522021-02-15 23:00:45 -0800360 // L2 PM counters MEs exceed max allowed OMCI payload size.
361 // So the request/responses are always multipart.
362 // First identify the attributes that are not requested in the current GET request.
363 // Then filter out those attributes from the responses in the current GET response.
364 unwantedAttributeMask := ^attributeMask
365 var i uint16
366 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
367 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
368 if (1<<(16-i))&unwantedAttributeMask > 0 {
369 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
370 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
371 }
372 }
373 }
374
Matteo Scandolof9d43412021-01-12 11:11:34 -0800375 return &omci.GetResponse{
376 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800377 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID,
378 EntityInstance: entityID,
379 },
380 Attributes: managedEntity.GetAttributeValueMap(),
381 AttributeMask: attributeMask,
382 Result: me.Success,
383 }
384}
385
386func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800387 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{
388 EntityID: entityID,
389 Attributes: me.AttributeValueMap{
390 "ManagedEntityId": entityID,
391 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
392 "ThresholdData12Id": 0,
393 "DropEvents": rand.Intn(100),
394 "Octets": rand.Intn(100),
395 "Packets": rand.Intn(100),
396 "BroadcastPackets": rand.Intn(100),
397 "MulticastPackets": rand.Intn(100),
398 "CrcErroredPackets": rand.Intn(100),
399 "UndersizePackets": rand.Intn(100),
400 "OversizePackets": rand.Intn(100),
401 "Packets64Octets": rand.Intn(100),
402 "Packets65To127Octets": rand.Intn(100),
403 "Packets128To255Octets": rand.Intn(100),
404 "Packets256To511Octets": rand.Intn(100),
405 "Packets512To1023Octets": rand.Intn(100),
406 "Packets1024To1518Octets": rand.Intn(100),
407 },
408 })
409
410 if meErr.GetError() != nil {
411 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error())
412 return nil
413 }
414
415 // L2 PM counters MEs exceed max allowed OMCI payload size.
416 // So the request/responses are always multipart.
417 // First identify the attributes that are not requested in the current GET request.
418 // Then filter out those attributes from the responses in the current GET response.
419 unwantedAttributeMask := ^attributeMask
420 var i uint16
421 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
422 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
423 if (1<<(16-i))&unwantedAttributeMask > 0 {
424 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
425 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
426 }
427 }
428 }
429
430 return &omci.GetResponse{
431 MeBasePacket: omci.MeBasePacket{
432 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID,
433 EntityInstance: entityID,
434 },
435 Attributes: managedEntity.GetAttributeValueMap(),
436 AttributeMask: attributeMask,
437 Result: me.Success,
438 }
439}
440
441func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800442 managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{
443 EntityID: entityID,
444 Attributes: me.AttributeValueMap{
445 "ManagedEntityId": entityID,
446 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
447 "ThresholdData12Id": 0,
448 "FcsErrors": rand.Intn(100),
449 "ExcessiveCollisionCounter": rand.Intn(100),
450 "LateCollisionCounter": rand.Intn(100),
451 "FramesTooLong": rand.Intn(100),
452 "BufferOverflowsOnReceive": rand.Intn(100),
453 "BufferOverflowsOnTransmit": rand.Intn(100),
454 "SingleCollisionFrameCounter": rand.Intn(100),
455 "MultipleCollisionsFrameCounter": rand.Intn(100),
456 "SqeCounter": rand.Intn(100),
457 "DeferredTransmissionCounter": rand.Intn(100),
458 "InternalMacTransmitErrorCounter": rand.Intn(100),
459 "CarrierSenseErrorCounter": rand.Intn(100),
460 "AlignmentErrorCounter": rand.Intn(100),
461 "InternalMacReceiveErrorCounter": rand.Intn(100),
462 },
463 })
464
465 if meErr.GetError() != nil {
466 omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error())
467 return nil
468 }
469
470 // L2 PM counters MEs exceed max allowed OMCI payload size.
471 // So the request/responses are always multipart.
472 // First identify the attributes that are not requested in the current GET request.
473 // Then filter out those attributes from the responses in the current GET response.
474 unwantedAttributeMask := ^attributeMask
475 var i uint16
476 for i = 1; i <= 16; i++ { // 1 and 16 because they are allowed valid min and max index keys in AttributeValueMap.
477 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
478 if (1<<(16-i))&unwantedAttributeMask > 0 {
479 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
480 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
481 }
482 }
483 }
484
485 return &omci.GetResponse{
486 MeBasePacket: omci.MeBasePacket{
487 EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID,
488 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800489 },
490 Attributes: managedEntity.GetAttributeValueMap(),
491 AttributeMask: attributeMask,
492 Result: me.Success,
493 }
494}
495
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800496func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
497 managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{
498 EntityID: entityID,
499 Attributes: me.AttributeValueMap{
500 "ManagedEntityId": entityID,
501 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
502 "ThresholdData12Id": 0,
503 "CorrectedBytes": rand.Intn(100),
504 "CorrectedCodeWords": rand.Intn(100),
505 "UncorrectableCodeWords": rand.Intn(100),
506 "TotalCodeWords": rand.Intn(100),
507 "FecSeconds": rand.Intn(100),
508 },
509 })
510
511 if meErr.GetError() != nil {
512 omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error())
513 return nil
514 }
515
516 // FEC History counter fits within single gem payload.
517 // No need of the logical we use in other Ethernet History counters or Gem Port History counters
518
519 return &omci.GetResponse{
520 MeBasePacket: omci.MeBasePacket{
521 EntityClass: me.FecPerformanceMonitoringHistoryDataClassID,
522 EntityInstance: entityID,
523 },
524 Attributes: managedEntity.GetAttributeValueMap(),
525 AttributeMask: attributeMask,
526 Result: me.Success,
527 }
528}
529
530func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse {
531 managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{
532 EntityID: entityID,
533 Attributes: me.AttributeValueMap{
534 "ManagedEntityId": entityID,
535 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
536 "ThresholdData12Id": 0,
537 "TransmittedGemFrames": rand.Intn(100),
538 "ReceivedGemFrames": rand.Intn(100),
539 "ReceivedPayloadBytes": rand.Intn(100),
540 "TransmittedPayloadBytes": rand.Intn(100),
541 "EncryptionKeyErrors": rand.Intn(100),
542 },
543 })
544
545 if meErr.GetError() != nil {
546 omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error())
547 return nil
548 }
549
550 // L2 PM counters MEs exceed max allowed OMCI payload size.
551 // So the request/responses are always multipart.
552 // First identify the attributes that are not requested in the current GET request.
553 // Then filter out those attributes from the responses in the current GET response.
554 unwantedAttributeMask := ^attributeMask
555 var i uint16
556 for i = 1; i <= 7; i++ { // 1 and 7 because they are allowed valid min and max index keys in AttributeValueMap.
557 // We leave out 0 because that is ManagedEntity and that is a default IE in the map
558 if (1<<(7-i))&unwantedAttributeMask > 0 {
559 if err := managedEntity.DeleteAttributeByIndex(uint(i)); err != nil {
560 omciLogger.Errorf("error deleting attribute at index=%v, err=%v", i, err)
561 }
562 }
563 }
564
565 return &omci.GetResponse{
566 MeBasePacket: omci.MeBasePacket{
567 EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID,
568 EntityInstance: entityID,
569 },
570 Attributes: managedEntity.GetAttributeValueMap(),
571 AttributeMask: attributeMask,
572 Result: me.Success,
573 }
574}
575
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800576func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800577 managedEntity, meErr := me.NewOnuData(me.ParamData{
578 EntityID: entityID,
579 Attributes: me.AttributeValueMap{
580 "ManagedEntityId": entityID,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800581 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800582 },
583 })
584
585 if meErr.GetError() != nil {
586 omciLogger.Errorf("NewOnuData %v", meErr.Error())
587 return nil
588 }
589
590 return &omci.GetResponse{
591 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800592 EntityClass: me.OnuDataClassID,
593 EntityInstance: entityID,
594 },
595 Attributes: managedEntity.GetAttributeValueMap(),
596 AttributeMask: attributeMask,
597 Result: me.Success,
598 }
599}
600
601func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
602 managedEntity, meErr := me.NewAniG(me.ParamData{
603 EntityID: entityID,
604 Attributes: me.AttributeValueMap{
605 "ManagedEntityId": entityID,
606 "SrIndication": 0,
607 "TotalTcontNumber": 0,
608 "GemBlockLength": 0,
609 "PiggybackDbaReporting": 0,
610 "Deprecated": 0,
611 "SignalFailThreshold": 0,
612 "SignalDegradeThreshold": 0,
613 "Arc": 0,
614 "ArcInterval": 0,
615 "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
616 "LowerOpticalThreshold": 0,
617 "UpperOpticalThreshold": 0,
618 "OnuResponseTime": 0,
619 "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
620 "LowerTransmitPowerThreshold": 0,
621 "UpperTransmitPowerThreshold": 0,
622 },
623 })
624
625 if meErr.GetError() != nil {
626 omciLogger.Errorf("NewAniG %v", meErr.Error())
627 return nil
628 }
629
630 return &omci.GetResponse{
631 MeBasePacket: omci.MeBasePacket{
632 EntityClass: me.AniGClassID,
633 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800634 },
635 Attributes: managedEntity.GetAttributeValueMap(),
636 AttributeMask: attributeMask,
637 Result: me.Success,
638 }
639}
640
641func toOctets(str string, size int) []byte {
642 asciiBytes := []byte(str)
643
644 if len(asciiBytes) < size {
645 missing := size - len(asciiBytes)
646 for i := 0; i < missing; i++ {
647 asciiBytes = append(asciiBytes, []byte{0x00}[0])
648 }
649 }
650 return asciiBytes
651}