blob: 384fc0b64de2e1206ee8da63daa4a6c8c7be875d [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
Girish Gowdra996d81e2021-04-21 16:16:27 -070048func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8, activeImageEntityId uint16, committedImageEntityId uint16, onuDown bool) ([]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:
Girish Gowdra996d81e2021-04-21 16:16:27 -070073 response = createUnigResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
Matteo Scandolof9d43412021-01-12 11:11:34 -080074 case me.PhysicalPathTerminationPointEthernetUniClassID:
Girish Gowdra996d81e2021-04-21 16:16:27 -070075 response = createPptpResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
Matteo Scandolof9d43412021-01-12 11:11:34 -080076 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 Scandolo78d5ee12021-04-14 11:11:32 -0700104 }).Error("cannot-Serialize-GetResponse")
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,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700207 }).Trace("received-get-software-image-request")
Matteo Scandolocedde462021-03-09 17:37:16 -0800208
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,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700243 }).Trace("Reporting SoftwareImage")
Matteo Scandolocedde462021-03-09 17:37:16 -0800244
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
Girish Gowdra996d81e2021-04-21 16:16:27 -0700263func createUnigResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
264 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
265 omciAdminState := 1
266 if !onuDown {
267 omciAdminState = 0
268 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800269 managedEntity, meErr := me.NewUniG(me.ParamData{
270 EntityID: entityID,
271 Attributes: me.AttributeValueMap{
272 "ManagedEntityId": entityID,
273 "Deprecated": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700274 "AdministrativeState": omciAdminState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800275 "ManagementCapability": 0,
276 "NonOmciManagementIdentifier": 1,
277 "RelayAgentOptions": 1,
278 },
279 })
280
281 if meErr.GetError() != nil {
282 omciLogger.Errorf("NewUniG %v", meErr.Error())
283 return nil
284 }
285
286 return &omci.GetResponse{
287 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800288 EntityClass: me.UniGClassID,
289 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800290 },
291 Attributes: managedEntity.GetAttributeValueMap(),
292 AttributeMask: attributeMask,
293 Result: me.Success,
294 }
295}
296
Girish Gowdra996d81e2021-04-21 16:16:27 -0700297func createPptpResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
298 // Valid values for oper_state are 0 (enabled) and 1 (disabled)
299 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
300 onuAdminState := 1
301 if !onuDown {
302 onuAdminState = 0
303 }
304 onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state
Matteo Scandolof9d43412021-01-12 11:11:34 -0800305 managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
306 EntityID: entityID,
307 Attributes: me.AttributeValueMap{
308 "ManagedEntityId": entityID,
309 "ExpectedType": 0,
310 "SensedType": 0,
311 "AutoDetectionConfiguration": 0,
312 "EthernetLoopbackConfiguration": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700313 "AdministrativeState": onuAdminState,
314 "OperationalState": onuOperState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800315 "ConfigurationInd": 0,
316 "MaxFrameSize": 0,
317 "DteOrDceInd": 0,
318 "PauseTime": 0,
319 "BridgedOrIpInd": 0,
320 "Arc": 0,
321 "ArcInterval": 0,
322 "PppoeFilter": 0,
323 "PowerControl": 0,
324 },
325 })
326
327 if meErr.GetError() != nil {
328 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
329 return nil
330 }
331
332 return &omci.GetResponse{
333 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800334 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
335 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800336 },
337 Attributes: managedEntity.GetAttributeValueMap(),
338 AttributeMask: attributeMask,
339 Result: me.Success,
340 }
341}
342
Girish Gowdraa539f522021-02-15 23:00:45 -0800343func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800344 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800345 EntityID: entityID,
346 Attributes: me.AttributeValueMap{
Girish Gowdraa539f522021-02-15 23:00:45 -0800347 "ManagedEntityId": entityID,
348 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
349 "ThresholdData12Id": 0,
350 "DropEvents": rand.Intn(100),
351 "Octets": rand.Intn(100),
352 "Packets": rand.Intn(100),
353 "BroadcastPackets": rand.Intn(100),
354 "MulticastPackets": rand.Intn(100),
355 "CrcErroredPackets": rand.Intn(100),
356 "UndersizePackets": rand.Intn(100),
357 "OversizePackets": rand.Intn(100),
358 "Packets64Octets": rand.Intn(100),
359 "Packets65To127Octets": rand.Intn(100),
360 "Packets128To255Octets": rand.Intn(100),
361 "Packets256To511Octets": rand.Intn(100),
362 "Packets512To1023Octets": rand.Intn(100),
363 "Packets1024To1518Octets": rand.Intn(100),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800364 },
365 })
366
367 if meErr.GetError() != nil {
Girish Gowdraa539f522021-02-15 23:00:45 -0800368 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error())
Matteo Scandolof9d43412021-01-12 11:11:34 -0800369 return nil
370 }
371
372 return &omci.GetResponse{
373 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800374 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID,
375 EntityInstance: entityID,
376 },
377 Attributes: managedEntity.GetAttributeValueMap(),
378 AttributeMask: attributeMask,
379 Result: me.Success,
380 }
381}
382
383func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800384 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{
385 EntityID: entityID,
386 Attributes: me.AttributeValueMap{
387 "ManagedEntityId": entityID,
388 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
389 "ThresholdData12Id": 0,
390 "DropEvents": rand.Intn(100),
391 "Octets": rand.Intn(100),
392 "Packets": rand.Intn(100),
393 "BroadcastPackets": rand.Intn(100),
394 "MulticastPackets": rand.Intn(100),
395 "CrcErroredPackets": rand.Intn(100),
396 "UndersizePackets": rand.Intn(100),
397 "OversizePackets": rand.Intn(100),
398 "Packets64Octets": rand.Intn(100),
399 "Packets65To127Octets": rand.Intn(100),
400 "Packets128To255Octets": rand.Intn(100),
401 "Packets256To511Octets": rand.Intn(100),
402 "Packets512To1023Octets": rand.Intn(100),
403 "Packets1024To1518Octets": rand.Intn(100),
404 },
405 })
406
407 if meErr.GetError() != nil {
408 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error())
409 return nil
410 }
411
Girish Gowdraa539f522021-02-15 23:00:45 -0800412 return &omci.GetResponse{
413 MeBasePacket: omci.MeBasePacket{
414 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID,
415 EntityInstance: entityID,
416 },
417 Attributes: managedEntity.GetAttributeValueMap(),
418 AttributeMask: attributeMask,
419 Result: me.Success,
420 }
421}
422
423func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800424 managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{
425 EntityID: entityID,
426 Attributes: me.AttributeValueMap{
427 "ManagedEntityId": entityID,
428 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
429 "ThresholdData12Id": 0,
430 "FcsErrors": rand.Intn(100),
431 "ExcessiveCollisionCounter": rand.Intn(100),
432 "LateCollisionCounter": rand.Intn(100),
433 "FramesTooLong": rand.Intn(100),
434 "BufferOverflowsOnReceive": rand.Intn(100),
435 "BufferOverflowsOnTransmit": rand.Intn(100),
436 "SingleCollisionFrameCounter": rand.Intn(100),
437 "MultipleCollisionsFrameCounter": rand.Intn(100),
438 "SqeCounter": rand.Intn(100),
439 "DeferredTransmissionCounter": rand.Intn(100),
440 "InternalMacTransmitErrorCounter": rand.Intn(100),
441 "CarrierSenseErrorCounter": rand.Intn(100),
442 "AlignmentErrorCounter": rand.Intn(100),
443 "InternalMacReceiveErrorCounter": rand.Intn(100),
444 },
445 })
446
447 if meErr.GetError() != nil {
448 omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error())
449 return nil
450 }
451
Girish Gowdraa539f522021-02-15 23:00:45 -0800452 return &omci.GetResponse{
453 MeBasePacket: omci.MeBasePacket{
454 EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID,
455 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800456 },
457 Attributes: managedEntity.GetAttributeValueMap(),
458 AttributeMask: attributeMask,
459 Result: me.Success,
460 }
461}
462
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800463func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
464 managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{
465 EntityID: entityID,
466 Attributes: me.AttributeValueMap{
467 "ManagedEntityId": entityID,
468 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
469 "ThresholdData12Id": 0,
470 "CorrectedBytes": rand.Intn(100),
471 "CorrectedCodeWords": rand.Intn(100),
472 "UncorrectableCodeWords": rand.Intn(100),
473 "TotalCodeWords": rand.Intn(100),
474 "FecSeconds": rand.Intn(100),
475 },
476 })
477
478 if meErr.GetError() != nil {
479 omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error())
480 return nil
481 }
482
483 // FEC History counter fits within single gem payload.
484 // No need of the logical we use in other Ethernet History counters or Gem Port History counters
485
486 return &omci.GetResponse{
487 MeBasePacket: omci.MeBasePacket{
488 EntityClass: me.FecPerformanceMonitoringHistoryDataClassID,
489 EntityInstance: entityID,
490 },
491 Attributes: managedEntity.GetAttributeValueMap(),
492 AttributeMask: attributeMask,
493 Result: me.Success,
494 }
495}
496
497func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse {
498 managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{
499 EntityID: entityID,
500 Attributes: me.AttributeValueMap{
501 "ManagedEntityId": entityID,
502 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
503 "ThresholdData12Id": 0,
504 "TransmittedGemFrames": rand.Intn(100),
505 "ReceivedGemFrames": rand.Intn(100),
506 "ReceivedPayloadBytes": rand.Intn(100),
507 "TransmittedPayloadBytes": rand.Intn(100),
508 "EncryptionKeyErrors": rand.Intn(100),
509 },
510 })
511
512 if meErr.GetError() != nil {
513 omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error())
514 return nil
515 }
516
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800517 return &omci.GetResponse{
518 MeBasePacket: omci.MeBasePacket{
519 EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID,
520 EntityInstance: entityID,
521 },
522 Attributes: managedEntity.GetAttributeValueMap(),
523 AttributeMask: attributeMask,
524 Result: me.Success,
525 }
526}
527
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800528func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800529 managedEntity, meErr := me.NewOnuData(me.ParamData{
530 EntityID: entityID,
531 Attributes: me.AttributeValueMap{
532 "ManagedEntityId": entityID,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800533 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800534 },
535 })
536
537 if meErr.GetError() != nil {
538 omciLogger.Errorf("NewOnuData %v", meErr.Error())
539 return nil
540 }
541
542 return &omci.GetResponse{
543 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800544 EntityClass: me.OnuDataClassID,
545 EntityInstance: entityID,
546 },
547 Attributes: managedEntity.GetAttributeValueMap(),
548 AttributeMask: attributeMask,
549 Result: me.Success,
550 }
551}
552
553func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
554 managedEntity, meErr := me.NewAniG(me.ParamData{
555 EntityID: entityID,
556 Attributes: me.AttributeValueMap{
557 "ManagedEntityId": entityID,
558 "SrIndication": 0,
559 "TotalTcontNumber": 0,
560 "GemBlockLength": 0,
561 "PiggybackDbaReporting": 0,
562 "Deprecated": 0,
563 "SignalFailThreshold": 0,
564 "SignalDegradeThreshold": 0,
565 "Arc": 0,
566 "ArcInterval": 0,
567 "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
568 "LowerOpticalThreshold": 0,
569 "UpperOpticalThreshold": 0,
570 "OnuResponseTime": 0,
571 "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
572 "LowerTransmitPowerThreshold": 0,
573 "UpperTransmitPowerThreshold": 0,
574 },
575 })
576
577 if meErr.GetError() != nil {
578 omciLogger.Errorf("NewAniG %v", meErr.Error())
579 return nil
580 }
581
582 return &omci.GetResponse{
583 MeBasePacket: omci.MeBasePacket{
584 EntityClass: me.AniGClassID,
585 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800586 },
587 Attributes: managedEntity.GetAttributeValueMap(),
588 AttributeMask: attributeMask,
589 Result: me.Success,
590 }
591}
592
593func toOctets(str string, size int) []byte {
594 asciiBytes := []byte(str)
595
596 if len(asciiBytes) < size {
597 missing := size - len(asciiBytes)
598 for i := 0; i < missing; i++ {
599 asciiBytes = append(asciiBytes, []byte{0x00}[0])
600 }
601 }
602 return asciiBytes
603}