blob: f8680a8df3b4be23a739aa6bd99cdd7958199e2d [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"
Elia Battistonac63b112022-01-12 18:40:49 +010023 "math/rand"
24 "strconv"
25
Matteo Scandolof9d43412021-01-12 11:11:34 -080026 "github.com/google/gopacket"
Andrea Campanella10426e22021-10-15 17:58:04 +020027 "github.com/opencord/omci-lib-go/v2"
28 me "github.com/opencord/omci-lib-go/v2/generated"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000029 "github.com/opencord/voltha-protos/v5/go/openolt"
Matteo Scandolof9d43412021-01-12 11:11:34 -080030 log "github.com/sirupsen/logrus"
Matteo Scandolof9d43412021-01-12 11:11:34 -080031)
32
33func ParseGetRequest(omciPkt gopacket.Packet) (*omci.GetRequest, error) {
34 msgLayer := omciPkt.Layer(omci.LayerTypeGetRequest)
35 if msgLayer == nil {
36 err := "omci Msg layer could not be detected for LayerTypeGetRequest"
37 omciLogger.Error(err)
38 return nil, errors.New(err)
39 }
40 msgObj, msgOk := msgLayer.(*omci.GetRequest)
41 if !msgOk {
42 err := "omci Msg layer could not be assigned for LayerTypeGetRequest"
43 omciLogger.Error(err)
44 return nil, errors.New(err)
45 }
46 return msgObj, nil
47}
48
Matteo Scandoloc00e97a2021-05-27 11:45:27 -070049func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8,
50 activeImageEntityId uint16, committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string,
51 committedImageVersion string, onuDown bool) ([]byte, error) {
Matteo Scandolof9d43412021-01-12 11:11:34 -080052 msgObj, err := ParseGetRequest(omciPkt)
Matteo Scandolof9d43412021-01-12 11:11:34 -080053 if err != nil {
54 return nil, err
55 }
Matteo Scandolof9d43412021-01-12 11:11:34 -080056 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 Scandoloc00e97a2021-05-27 11:45:27 -070069 response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance,
70 activeImageEntityId, committedImageEntityId, standbyImageVersion, activeImageVersion, committedImageVersion)
Matteo Scandolof9d43412021-01-12 11:11:34 -080071 case me.IpHostConfigDataClassID:
72 response = createIpHostResponse(msgObj.AttributeMask, msgObj.EntityInstance)
Elia Battistonac63b112022-01-12 18:40:49 +010073 case me.VoipConfigDataClassID:
74 response = createVoipConfigDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
Matteo Scandolof9d43412021-01-12 11:11:34 -080075 case me.UniGClassID:
Girish Gowdra996d81e2021-04-21 16:16:27 -070076 response = createUnigResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
Matteo Scandolof9d43412021-01-12 11:11:34 -080077 case me.PhysicalPathTerminationPointEthernetUniClassID:
Elia Battistonac63b112022-01-12 18:40:49 +010078 response = createPptpEthernetResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
79 case me.PhysicalPathTerminationPointPotsUniClassID:
80 response = createPptpPotsResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
Matteo Scandolof9d43412021-01-12 11:11:34 -080081 case me.AniGClassID:
82 response = createAnigResponse(msgObj.AttributeMask, msgObj.EntityInstance)
83 case me.OnuDataClassID:
Matteo Scandolo992a23e2021-02-04 15:35:04 -080084 response = createOnuDataResponse(msgObj.AttributeMask, msgObj.EntityInstance, mds)
Girish Gowdraa539f522021-02-15 23:00:45 -080085 case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID:
86 response = createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance)
87 case me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID:
88 response = createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance)
89 case me.EthernetPerformanceMonitoringHistoryDataClassID:
90 response = createEthernetPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
Girish Gowdra6d9a1a42021-03-05 16:07:15 -080091 case me.FecPerformanceMonitoringHistoryDataClassID:
92 response = createFecPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
93 case me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID:
94 response = createGemPortNetworkCtpPerformanceMonitoringHistoryData(msgObj.AttributeMask, msgObj.EntityInstance)
Himani Chawla6bd190a2021-07-09 15:31:01 +053095 case me.EthernetFrameExtendedPmClassID,
96 me.EthernetFrameExtendedPm64BitClassID:
97 response = createEthernetFrameExtendedPmGetResponse(msgObj.EntityClass, msgObj.AttributeMask, msgObj.EntityInstance)
Matteo Scandolof9d43412021-01-12 11:11:34 -080098 default:
99 omciLogger.WithFields(log.Fields{
100 "EntityClass": msgObj.EntityClass,
101 "EntityInstance": msgObj.EntityInstance,
102 "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask),
103 }).Warnf("do-not-know-how-to-handle-get-request-for-me-class")
104 return nil, nil
105 }
106
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800107 pkt, err := Serialize(omci.GetResponseType, response, omciMsg.TransactionID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800108 if err != nil {
109 omciLogger.WithFields(log.Fields{
110 "Err": err,
111 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
Matteo Scandolo78d5ee12021-04-14 11:11:32 -0700112 }).Error("cannot-Serialize-GetResponse")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800113 return nil, err
114 }
115
116 log.WithFields(log.Fields{
117 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
118 "pkt": hex.EncodeToString(pkt),
119 }).Trace("omci-get-response")
120
121 return pkt, nil
122}
123
124func createOnu2gResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
125
126 managedEntity, meErr := me.NewOnu2G(me.ParamData{
127 EntityID: entityID,
128 Attributes: me.AttributeValueMap{
129 "ManagedEntityId": entityID,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700130 "EquipmentId": ToOctets("12345123451234512345", 20),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800131 "OpticalNetworkUnitManagementAndControlChannelOmccVersion": 180,
132 "VendorProductCode": 0,
133 "SecurityCapability": 1,
134 "SecurityMode": 1,
135 "TotalPriorityQueueNumber": 1,
136 "TotalTrafficSchedulerNumber": 1,
137 "Deprecated": 1,
138 "TotalGemPortIdNumber": 32,
139 "Sysuptime": 319389947, // NOTE need to be smarter?
140 "ConnectivityCapability": 127,
141 "CurrentConnectivityMode": 5,
142 "QualityOfServiceQosConfigurationFlexibility": 48,
143 "PriorityQueueScaleFactor": 1,
144 },
145 })
146
147 if meErr.GetError() != nil {
148 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
149 return nil
150 }
151
152 return &omci.GetResponse{
153 MeBasePacket: omci.MeBasePacket{
154 EntityClass: me.Onu2GClassID,
155 },
156 Attributes: managedEntity.GetAttributeValueMap(),
157 AttributeMask: attributeMask,
158 Result: me.Success,
159 }
160}
161
Matteo Scandolo5863f002021-02-08 08:08:14 -0800162func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse {
163
164 managedEntity, meErr := me.NewOnuG(me.ParamData{
165 EntityID: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800166 Attributes: me.AttributeValueMap{
167 "ManagedEntityId": entityID,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700168 "VendorId": ToOctets("BBSM", 4),
169 "Version": ToOctets("v0.0.1", 14),
Matteo Scandolo5863f002021-02-08 08:08:14 -0800170 "SerialNumber": append(onuSn.VendorId, onuSn.VendorSpecific...),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800171 "TrafficManagementOption": 0,
172 "Deprecated": 0,
173 "BatteryBackup": 0,
174 "AdministrativeState": 0,
175 "OperationalState": 0,
176 "OnuSurvivalTime": 10,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700177 "LogicalOnuId": ToOctets("BBSM", 24),
178 "LogicalPassword": ToOctets("BBSM", 12),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800179 "CredentialsStatus": 0,
180 "ExtendedTcLayerOptions": 0,
181 },
Matteo Scandolo5863f002021-02-08 08:08:14 -0800182 })
183
184 if meErr.GetError() != nil {
185 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
186 return nil
Matteo Scandolof9d43412021-01-12 11:11:34 -0800187 }
Matteo Scandolo5863f002021-02-08 08:08:14 -0800188
189 return &omci.GetResponse{
190 MeBasePacket: omci.MeBasePacket{
191 EntityClass: me.OnuGClassID,
192 },
193 Attributes: managedEntity.GetAttributeValueMap(),
194 AttributeMask: attributeMask,
195 Result: me.Success,
196 }
197
198 //return &omci.GetResponse{
199 // MeBasePacket: omci.MeBasePacket{
200 // EntityClass: me.OnuGClassID,
201 // EntityInstance: entityID,
202 // },
203 // Attributes: me.AttributeValueMap{
204 //
205 // },
206 // Result: me.Success,
207 // AttributeMask: attributeMask,
208 //}
Matteo Scandolof9d43412021-01-12 11:11:34 -0800209}
210
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700211func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16, activeImageEntityId uint16,
212 committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string, committedImageVersion string) *omci.GetResponse {
Matteo Scandolocedde462021-03-09 17:37:16 -0800213
214 omciLogger.WithFields(log.Fields{
215 "EntityInstance": entityInstance,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700216 "AttributeMask": attributeMask,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700217 }).Trace("received-get-software-image-request")
Matteo Scandolocedde462021-03-09 17:37:16 -0800218
219 // Only one image can be active and committed
220 committed := 0
221 active := 0
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700222 version := standbyImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -0800223 if entityInstance == activeImageEntityId {
224 active = 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700225 version = activeImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -0800226 }
227 if entityInstance == committedImageEntityId {
228 committed = 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700229 version = committedImageVersion
230 }
231
232 imageHash, err := hex.DecodeString(hex.EncodeToString([]byte(version)))
233 if err != nil {
234 omciLogger.WithFields(log.Fields{
235 "entityId": entityInstance,
236 "active": active,
237 "committed": committed,
238 "err": err,
239 }).Error("cannot-generate-image-hash")
Matteo Scandolocedde462021-03-09 17:37:16 -0800240 }
241
Matteo Scandolof9d43412021-01-12 11:11:34 -0800242 // 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 -0800243 res := &omci.GetResponse{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800244 MeBasePacket: omci.MeBasePacket{
245 EntityClass: me.SoftwareImageClassID,
246 EntityInstance: entityInstance,
247 },
248 Attributes: me.AttributeValueMap{
249 "ManagedEntityId": 0,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700250 "Version": ToOctets(version, 14),
Matteo Scandolocedde462021-03-09 17:37:16 -0800251 "IsCommitted": committed,
252 "IsActive": active,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800253 "IsValid": 1,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700254 "ProductCode": ToOctets("BBSIM-ONU", 25),
255 "ImageHash": imageHash,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800256 },
257 Result: me.Success,
258 AttributeMask: attributeMask,
259 }
Matteo Scandolocedde462021-03-09 17:37:16 -0800260
261 omciLogger.WithFields(log.Fields{
262 "omciMessage": res,
263 "entityId": entityInstance,
264 "active": active,
265 "committed": committed,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700266 }).Trace("Reporting SoftwareImage")
Matteo Scandolocedde462021-03-09 17:37:16 -0800267
268 return res
Matteo Scandolof9d43412021-01-12 11:11:34 -0800269}
270
271func createIpHostResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
272 return &omci.GetResponse{
273 MeBasePacket: omci.MeBasePacket{
274 EntityClass: me.IpHostConfigDataClassID,
275 EntityInstance: entityInstance,
276 },
277 Attributes: me.AttributeValueMap{
278 "ManagedEntityId": 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700279 "MacAddress": ToOctets("aabbcc", 6),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800280 },
281 Result: me.Success,
282 AttributeMask: attributeMask,
283 }
284}
285
Elia Battistonac63b112022-01-12 18:40:49 +0100286func createVoipConfigDataResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
287 return &omci.GetResponse{
288 MeBasePacket: omci.MeBasePacket{
289 EntityClass: me.VoipConfigDataClassID,
290 EntityInstance: entityInstance,
291 },
292 Attributes: me.AttributeValueMap{
293 "ManagedEntityId": 0,
294 "AvailableSignallingProtocols": 1,
295 "SignallingProtocolUsed": 1,
296 "AvailableVoipConfigurationMethods": 1,
297 "VoipConfigurationMethodUsed": 1,
298 "VoipConfigurationAddressPointer": 0xFFFF,
299 "VoipConfigurationState": 0,
300 "RetrieveProfile": 0,
301 "ProfileVersion": 0,
302 },
303 Result: me.Success,
304 AttributeMask: attributeMask,
305 }
306}
307
Girish Gowdra996d81e2021-04-21 16:16:27 -0700308func createUnigResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
309 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
310 omciAdminState := 1
311 if !onuDown {
312 omciAdminState = 0
313 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800314 managedEntity, meErr := me.NewUniG(me.ParamData{
315 EntityID: entityID,
316 Attributes: me.AttributeValueMap{
317 "ManagedEntityId": entityID,
318 "Deprecated": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700319 "AdministrativeState": omciAdminState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800320 "ManagementCapability": 0,
321 "NonOmciManagementIdentifier": 1,
322 "RelayAgentOptions": 1,
323 },
324 })
325
326 if meErr.GetError() != nil {
327 omciLogger.Errorf("NewUniG %v", meErr.Error())
328 return nil
329 }
330
331 return &omci.GetResponse{
332 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800333 EntityClass: me.UniGClassID,
334 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800335 },
336 Attributes: managedEntity.GetAttributeValueMap(),
337 AttributeMask: attributeMask,
338 Result: me.Success,
339 }
340}
341
Elia Battistonac63b112022-01-12 18:40:49 +0100342func createPptpEthernetResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
Girish Gowdra996d81e2021-04-21 16:16:27 -0700343 // Valid values for oper_state are 0 (enabled) and 1 (disabled)
344 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
345 onuAdminState := 1
346 if !onuDown {
347 onuAdminState = 0
348 }
349 onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state
Matteo Scandolof9d43412021-01-12 11:11:34 -0800350 managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
351 EntityID: entityID,
352 Attributes: me.AttributeValueMap{
353 "ManagedEntityId": entityID,
354 "ExpectedType": 0,
355 "SensedType": 0,
356 "AutoDetectionConfiguration": 0,
357 "EthernetLoopbackConfiguration": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700358 "AdministrativeState": onuAdminState,
359 "OperationalState": onuOperState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800360 "ConfigurationInd": 0,
361 "MaxFrameSize": 0,
362 "DteOrDceInd": 0,
363 "PauseTime": 0,
364 "BridgedOrIpInd": 0,
365 "Arc": 0,
366 "ArcInterval": 0,
367 "PppoeFilter": 0,
368 "PowerControl": 0,
369 },
370 })
371
372 if meErr.GetError() != nil {
373 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
374 return nil
375 }
376
377 return &omci.GetResponse{
378 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800379 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
380 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800381 },
382 Attributes: managedEntity.GetAttributeValueMap(),
383 AttributeMask: attributeMask,
384 Result: me.Success,
385 }
386}
387
Elia Battistonac63b112022-01-12 18:40:49 +0100388func createPptpPotsResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
389 // Valid values for oper_state are 0 (enabled) and 1 (disabled)
390 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
391 onuAdminState := 1
392 if !onuDown {
393 onuAdminState = 0
394 }
395 onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state
396 managedEntity, meErr := me.NewPhysicalPathTerminationPointPotsUni(me.ParamData{
397 EntityID: entityID,
398 Attributes: me.AttributeValueMap{
399 "ManagedEntityId": entityID,
400 "AdministrativeState": onuAdminState,
401 "Deprecated": 0,
402 "Arc": 0,
403 "ArcInterval": 0,
404 "Impedance": 0,
405 "TransmissionPath": 0,
406 "RxGain": 0,
407 "TxGain": 0,
408 "OperationalState": onuOperState,
409 "HookState": 0,
410 "PotsHoldoverTime": 0,
411 "NominalFeedVoltage": 0,
412 "LossOfSoftswitch": 0,
413 },
414 })
415
416 if meErr.GetError() != nil {
417 omciLogger.Errorf("NewPhysicalPathTerminationPointPotsUni %v", meErr.Error())
418 return nil
419 }
420
421 return &omci.GetResponse{
422 MeBasePacket: omci.MeBasePacket{
423 EntityClass: me.PhysicalPathTerminationPointPotsUniClassID,
424 EntityInstance: entityID,
425 },
426 Attributes: managedEntity.GetAttributeValueMap(),
427 AttributeMask: attributeMask,
428 Result: me.Success,
429 }
430}
431
Girish Gowdraa539f522021-02-15 23:00:45 -0800432func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800433 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800434 EntityID: entityID,
435 Attributes: me.AttributeValueMap{
Girish Gowdraa539f522021-02-15 23:00:45 -0800436 "ManagedEntityId": entityID,
437 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
438 "ThresholdData12Id": 0,
439 "DropEvents": rand.Intn(100),
440 "Octets": rand.Intn(100),
441 "Packets": rand.Intn(100),
442 "BroadcastPackets": rand.Intn(100),
443 "MulticastPackets": rand.Intn(100),
444 "CrcErroredPackets": rand.Intn(100),
445 "UndersizePackets": rand.Intn(100),
446 "OversizePackets": rand.Intn(100),
447 "Packets64Octets": rand.Intn(100),
448 "Packets65To127Octets": rand.Intn(100),
449 "Packets128To255Octets": rand.Intn(100),
450 "Packets256To511Octets": rand.Intn(100),
451 "Packets512To1023Octets": rand.Intn(100),
452 "Packets1024To1518Octets": rand.Intn(100),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800453 },
454 })
455
456 if meErr.GetError() != nil {
Girish Gowdraa539f522021-02-15 23:00:45 -0800457 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error())
Matteo Scandolof9d43412021-01-12 11:11:34 -0800458 return nil
459 }
460
461 return &omci.GetResponse{
462 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800463 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID,
464 EntityInstance: entityID,
465 },
466 Attributes: managedEntity.GetAttributeValueMap(),
467 AttributeMask: attributeMask,
468 Result: me.Success,
469 }
470}
471
472func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800473 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(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 "DropEvents": rand.Intn(100),
480 "Octets": rand.Intn(100),
481 "Packets": rand.Intn(100),
482 "BroadcastPackets": rand.Intn(100),
483 "MulticastPackets": rand.Intn(100),
484 "CrcErroredPackets": rand.Intn(100),
485 "UndersizePackets": rand.Intn(100),
486 "OversizePackets": rand.Intn(100),
487 "Packets64Octets": rand.Intn(100),
488 "Packets65To127Octets": rand.Intn(100),
489 "Packets128To255Octets": rand.Intn(100),
490 "Packets256To511Octets": rand.Intn(100),
491 "Packets512To1023Octets": rand.Intn(100),
492 "Packets1024To1518Octets": rand.Intn(100),
493 },
494 })
495
496 if meErr.GetError() != nil {
497 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error())
498 return nil
499 }
500
Girish Gowdraa539f522021-02-15 23:00:45 -0800501 return &omci.GetResponse{
502 MeBasePacket: omci.MeBasePacket{
503 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID,
504 EntityInstance: entityID,
505 },
506 Attributes: managedEntity.GetAttributeValueMap(),
507 AttributeMask: attributeMask,
508 Result: me.Success,
509 }
510}
511
512func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800513 managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{
514 EntityID: entityID,
515 Attributes: me.AttributeValueMap{
516 "ManagedEntityId": entityID,
517 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
518 "ThresholdData12Id": 0,
519 "FcsErrors": rand.Intn(100),
520 "ExcessiveCollisionCounter": rand.Intn(100),
521 "LateCollisionCounter": rand.Intn(100),
522 "FramesTooLong": rand.Intn(100),
523 "BufferOverflowsOnReceive": rand.Intn(100),
524 "BufferOverflowsOnTransmit": rand.Intn(100),
525 "SingleCollisionFrameCounter": rand.Intn(100),
526 "MultipleCollisionsFrameCounter": rand.Intn(100),
527 "SqeCounter": rand.Intn(100),
528 "DeferredTransmissionCounter": rand.Intn(100),
529 "InternalMacTransmitErrorCounter": rand.Intn(100),
530 "CarrierSenseErrorCounter": rand.Intn(100),
531 "AlignmentErrorCounter": rand.Intn(100),
532 "InternalMacReceiveErrorCounter": rand.Intn(100),
533 },
534 })
535
536 if meErr.GetError() != nil {
537 omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error())
538 return nil
539 }
540
Girish Gowdraa539f522021-02-15 23:00:45 -0800541 return &omci.GetResponse{
542 MeBasePacket: omci.MeBasePacket{
543 EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID,
544 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800545 },
546 Attributes: managedEntity.GetAttributeValueMap(),
547 AttributeMask: attributeMask,
548 Result: me.Success,
549 }
550}
551
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800552func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
553 managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{
554 EntityID: entityID,
555 Attributes: me.AttributeValueMap{
556 "ManagedEntityId": entityID,
557 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
558 "ThresholdData12Id": 0,
559 "CorrectedBytes": rand.Intn(100),
560 "CorrectedCodeWords": rand.Intn(100),
561 "UncorrectableCodeWords": rand.Intn(100),
562 "TotalCodeWords": rand.Intn(100),
563 "FecSeconds": rand.Intn(100),
564 },
565 })
566
567 if meErr.GetError() != nil {
568 omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error())
569 return nil
570 }
571
572 // FEC History counter fits within single gem payload.
573 // No need of the logical we use in other Ethernet History counters or Gem Port History counters
574
575 return &omci.GetResponse{
576 MeBasePacket: omci.MeBasePacket{
577 EntityClass: me.FecPerformanceMonitoringHistoryDataClassID,
578 EntityInstance: entityID,
579 },
580 Attributes: managedEntity.GetAttributeValueMap(),
581 AttributeMask: attributeMask,
582 Result: me.Success,
583 }
584}
585
586func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse {
587 managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{
588 EntityID: entityID,
589 Attributes: me.AttributeValueMap{
590 "ManagedEntityId": entityID,
591 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
592 "ThresholdData12Id": 0,
593 "TransmittedGemFrames": rand.Intn(100),
594 "ReceivedGemFrames": rand.Intn(100),
595 "ReceivedPayloadBytes": rand.Intn(100),
596 "TransmittedPayloadBytes": rand.Intn(100),
597 "EncryptionKeyErrors": rand.Intn(100),
598 },
599 })
600
601 if meErr.GetError() != nil {
602 omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error())
603 return nil
604 }
605
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800606 return &omci.GetResponse{
607 MeBasePacket: omci.MeBasePacket{
608 EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID,
609 EntityInstance: entityID,
610 },
611 Attributes: managedEntity.GetAttributeValueMap(),
612 AttributeMask: attributeMask,
613 Result: me.Success,
614 }
615}
616
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800617func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800618 managedEntity, meErr := me.NewOnuData(me.ParamData{
619 EntityID: entityID,
620 Attributes: me.AttributeValueMap{
621 "ManagedEntityId": entityID,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800622 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800623 },
624 })
625
626 if meErr.GetError() != nil {
627 omciLogger.Errorf("NewOnuData %v", meErr.Error())
628 return nil
629 }
630
631 return &omci.GetResponse{
632 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800633 EntityClass: me.OnuDataClassID,
634 EntityInstance: entityID,
635 },
636 Attributes: managedEntity.GetAttributeValueMap(),
637 AttributeMask: attributeMask,
638 Result: me.Success,
639 }
640}
641
642func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
643 managedEntity, meErr := me.NewAniG(me.ParamData{
644 EntityID: entityID,
645 Attributes: me.AttributeValueMap{
646 "ManagedEntityId": entityID,
647 "SrIndication": 0,
648 "TotalTcontNumber": 0,
649 "GemBlockLength": 0,
650 "PiggybackDbaReporting": 0,
651 "Deprecated": 0,
652 "SignalFailThreshold": 0,
653 "SignalDegradeThreshold": 0,
654 "Arc": 0,
655 "ArcInterval": 0,
656 "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
657 "LowerOpticalThreshold": 0,
658 "UpperOpticalThreshold": 0,
659 "OnuResponseTime": 0,
660 "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
661 "LowerTransmitPowerThreshold": 0,
662 "UpperTransmitPowerThreshold": 0,
663 },
664 })
665
666 if meErr.GetError() != nil {
667 omciLogger.Errorf("NewAniG %v", meErr.Error())
668 return nil
669 }
670
671 return &omci.GetResponse{
672 MeBasePacket: omci.MeBasePacket{
673 EntityClass: me.AniGClassID,
674 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800675 },
676 Attributes: managedEntity.GetAttributeValueMap(),
677 AttributeMask: attributeMask,
678 Result: me.Success,
679 }
680}
681
Himani Chawla6bd190a2021-07-09 15:31:01 +0530682func createEthernetFrameExtendedPmGetResponse(meClass me.ClassID, attributeMask uint16, entityID uint16) *omci.GetResponse {
683
684 callback := me.NewEthernetFrameExtendedPm
685 if meClass != me.EthernetFrameExtendedPmClassID {
686 callback = me.NewEthernetFrameExtendedPm64Bit
687 }
Himani Chawla908a1f52022-01-27 14:39:44 +0530688 attr := me.AttributeValueMap{
689 "ManagedEntityId": entityID,
690 "DropEvents": 100,
691 "Octets": 101,
692 "Frames": 102,
693 "BroadcastFrames": 103,
694 "MulticastFrames": 104,
695 "CrcErroredFrames": 105,
696 "UndersizeFrames": 106,
697 "OversizeFrames": 107,
698 "Frames64Octets": 108,
699 "Frames65To127Octets": 109,
700 "Frames128To255Octets": 110,
701 "Frames256To511Octets": 111,
702 "Frames512To1023Octets": 112,
703 "Frames1024To1518Octets": 113,
704 }
Himani Chawla6bd190a2021-07-09 15:31:01 +0530705 managedEntity, meErr := callback(me.ParamData{
Himani Chawla908a1f52022-01-27 14:39:44 +0530706 EntityID: entityID,
707 Attributes: attr,
Himani Chawla6bd190a2021-07-09 15:31:01 +0530708 })
709
710 if meErr.GetError() != nil {
711 omciLogger.Errorf("NewEthernetFrameExtendedPm %v", meErr.Error())
712 return nil
713 }
714
715 return &omci.GetResponse{
716 MeBasePacket: omci.MeBasePacket{
717 EntityClass: meClass,
718 EntityInstance: entityID,
719 },
720 Attributes: managedEntity.GetAttributeValueMap(),
721 AttributeMask: attributeMask,
722 Result: me.Success,
723 }
724}
725
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700726func ToOctets(str string, size int) []byte {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800727 asciiBytes := []byte(str)
728
729 if len(asciiBytes) < size {
730 missing := size - len(asciiBytes)
731 for i := 0; i < missing; i++ {
732 asciiBytes = append(asciiBytes, []byte{0x00}[0])
733 }
734 }
735 return asciiBytes
736}