blob: 1f76a0da2e24ac92acba15459db70cb0c3b4eeae [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
53 msgObj, err := ParseGetRequest(omciPkt)
54
55 if err != nil {
56 return nil, err
57 }
58
59 omciLogger.WithFields(log.Fields{
60 "EntityClass": msgObj.EntityClass,
61 "EntityInstance": msgObj.EntityInstance,
62 "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask),
Matteo Scandolo992a23e2021-02-04 15:35:04 -080063 }).Trace("received-omci-get-request")
Matteo Scandolof9d43412021-01-12 11:11:34 -080064
65 var response *omci.GetResponse
66 switch msgObj.EntityClass {
67 case me.Onu2GClassID:
68 response = createOnu2gResponse(msgObj.AttributeMask, msgObj.EntityInstance)
69 case me.OnuGClassID:
Matteo Scandolo5863f002021-02-08 08:08:14 -080070 response = createOnugResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuSn)
Matteo Scandolof9d43412021-01-12 11:11:34 -080071 case me.SoftwareImageClassID:
Matteo Scandoloc00e97a2021-05-27 11:45:27 -070072 response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance,
73 activeImageEntityId, committedImageEntityId, standbyImageVersion, activeImageVersion, committedImageVersion)
Matteo Scandolof9d43412021-01-12 11:11:34 -080074 case me.IpHostConfigDataClassID:
75 response = createIpHostResponse(msgObj.AttributeMask, msgObj.EntityInstance)
Elia Battistonac63b112022-01-12 18:40:49 +010076 case me.VoipConfigDataClassID:
77 response = createVoipConfigDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
Matteo Scandolof9d43412021-01-12 11:11:34 -080078 case me.UniGClassID:
Girish Gowdra996d81e2021-04-21 16:16:27 -070079 response = createUnigResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
Matteo Scandolof9d43412021-01-12 11:11:34 -080080 case me.PhysicalPathTerminationPointEthernetUniClassID:
Elia Battistonac63b112022-01-12 18:40:49 +010081 response = createPptpEthernetResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
82 case me.PhysicalPathTerminationPointPotsUniClassID:
83 response = createPptpPotsResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
Matteo Scandolof9d43412021-01-12 11:11:34 -080084 case me.AniGClassID:
85 response = createAnigResponse(msgObj.AttributeMask, msgObj.EntityInstance)
86 case me.OnuDataClassID:
Matteo Scandolo992a23e2021-02-04 15:35:04 -080087 response = createOnuDataResponse(msgObj.AttributeMask, msgObj.EntityInstance, mds)
Girish Gowdraa539f522021-02-15 23:00:45 -080088 case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID:
89 response = createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance)
90 case me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID:
91 response = createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance)
92 case me.EthernetPerformanceMonitoringHistoryDataClassID:
93 response = createEthernetPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
Girish Gowdra6d9a1a42021-03-05 16:07:15 -080094 case me.FecPerformanceMonitoringHistoryDataClassID:
95 response = createFecPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
96 case me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID:
97 response = createGemPortNetworkCtpPerformanceMonitoringHistoryData(msgObj.AttributeMask, msgObj.EntityInstance)
Himani Chawla6bd190a2021-07-09 15:31:01 +053098 case me.EthernetFrameExtendedPmClassID,
99 me.EthernetFrameExtendedPm64BitClassID:
100 response = createEthernetFrameExtendedPmGetResponse(msgObj.EntityClass, msgObj.AttributeMask, msgObj.EntityInstance)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800101 default:
102 omciLogger.WithFields(log.Fields{
103 "EntityClass": msgObj.EntityClass,
104 "EntityInstance": msgObj.EntityInstance,
105 "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask),
106 }).Warnf("do-not-know-how-to-handle-get-request-for-me-class")
107 return nil, nil
108 }
109
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800110 pkt, err := Serialize(omci.GetResponseType, response, omciMsg.TransactionID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800111 if err != nil {
112 omciLogger.WithFields(log.Fields{
113 "Err": err,
114 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
Matteo Scandolo78d5ee12021-04-14 11:11:32 -0700115 }).Error("cannot-Serialize-GetResponse")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800116 return nil, err
117 }
118
119 log.WithFields(log.Fields{
120 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
121 "pkt": hex.EncodeToString(pkt),
122 }).Trace("omci-get-response")
123
124 return pkt, nil
125}
126
127func createOnu2gResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
128
129 managedEntity, meErr := me.NewOnu2G(me.ParamData{
130 EntityID: entityID,
131 Attributes: me.AttributeValueMap{
132 "ManagedEntityId": entityID,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700133 "EquipmentId": ToOctets("12345123451234512345", 20),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800134 "OpticalNetworkUnitManagementAndControlChannelOmccVersion": 180,
135 "VendorProductCode": 0,
136 "SecurityCapability": 1,
137 "SecurityMode": 1,
138 "TotalPriorityQueueNumber": 1,
139 "TotalTrafficSchedulerNumber": 1,
140 "Deprecated": 1,
141 "TotalGemPortIdNumber": 32,
142 "Sysuptime": 319389947, // NOTE need to be smarter?
143 "ConnectivityCapability": 127,
144 "CurrentConnectivityMode": 5,
145 "QualityOfServiceQosConfigurationFlexibility": 48,
146 "PriorityQueueScaleFactor": 1,
147 },
148 })
149
150 if meErr.GetError() != nil {
151 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
152 return nil
153 }
154
155 return &omci.GetResponse{
156 MeBasePacket: omci.MeBasePacket{
157 EntityClass: me.Onu2GClassID,
158 },
159 Attributes: managedEntity.GetAttributeValueMap(),
160 AttributeMask: attributeMask,
161 Result: me.Success,
162 }
163}
164
Matteo Scandolo5863f002021-02-08 08:08:14 -0800165func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse {
166
167 managedEntity, meErr := me.NewOnuG(me.ParamData{
168 EntityID: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800169 Attributes: me.AttributeValueMap{
170 "ManagedEntityId": entityID,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700171 "VendorId": ToOctets("BBSM", 4),
172 "Version": ToOctets("v0.0.1", 14),
Matteo Scandolo5863f002021-02-08 08:08:14 -0800173 "SerialNumber": append(onuSn.VendorId, onuSn.VendorSpecific...),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800174 "TrafficManagementOption": 0,
175 "Deprecated": 0,
176 "BatteryBackup": 0,
177 "AdministrativeState": 0,
178 "OperationalState": 0,
179 "OnuSurvivalTime": 10,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700180 "LogicalOnuId": ToOctets("BBSM", 24),
181 "LogicalPassword": ToOctets("BBSM", 12),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800182 "CredentialsStatus": 0,
183 "ExtendedTcLayerOptions": 0,
184 },
Matteo Scandolo5863f002021-02-08 08:08:14 -0800185 })
186
187 if meErr.GetError() != nil {
188 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
189 return nil
Matteo Scandolof9d43412021-01-12 11:11:34 -0800190 }
Matteo Scandolo5863f002021-02-08 08:08:14 -0800191
192 return &omci.GetResponse{
193 MeBasePacket: omci.MeBasePacket{
194 EntityClass: me.OnuGClassID,
195 },
196 Attributes: managedEntity.GetAttributeValueMap(),
197 AttributeMask: attributeMask,
198 Result: me.Success,
199 }
200
201 //return &omci.GetResponse{
202 // MeBasePacket: omci.MeBasePacket{
203 // EntityClass: me.OnuGClassID,
204 // EntityInstance: entityID,
205 // },
206 // Attributes: me.AttributeValueMap{
207 //
208 // },
209 // Result: me.Success,
210 // AttributeMask: attributeMask,
211 //}
Matteo Scandolof9d43412021-01-12 11:11:34 -0800212}
213
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700214func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16, activeImageEntityId uint16,
215 committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string, committedImageVersion string) *omci.GetResponse {
Matteo Scandolocedde462021-03-09 17:37:16 -0800216
217 omciLogger.WithFields(log.Fields{
218 "EntityInstance": entityInstance,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700219 "AttributeMask": attributeMask,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700220 }).Trace("received-get-software-image-request")
Matteo Scandolocedde462021-03-09 17:37:16 -0800221
222 // Only one image can be active and committed
223 committed := 0
224 active := 0
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700225 version := standbyImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -0800226 if entityInstance == activeImageEntityId {
227 active = 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700228 version = activeImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -0800229 }
230 if entityInstance == committedImageEntityId {
231 committed = 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700232 version = committedImageVersion
233 }
234
235 imageHash, err := hex.DecodeString(hex.EncodeToString([]byte(version)))
236 if err != nil {
237 omciLogger.WithFields(log.Fields{
238 "entityId": entityInstance,
239 "active": active,
240 "committed": committed,
241 "err": err,
242 }).Error("cannot-generate-image-hash")
Matteo Scandolocedde462021-03-09 17:37:16 -0800243 }
244
Matteo Scandolof9d43412021-01-12 11:11:34 -0800245 // 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 -0800246 res := &omci.GetResponse{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800247 MeBasePacket: omci.MeBasePacket{
248 EntityClass: me.SoftwareImageClassID,
249 EntityInstance: entityInstance,
250 },
251 Attributes: me.AttributeValueMap{
252 "ManagedEntityId": 0,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700253 "Version": ToOctets(version, 14),
Matteo Scandolocedde462021-03-09 17:37:16 -0800254 "IsCommitted": committed,
255 "IsActive": active,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800256 "IsValid": 1,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700257 "ProductCode": ToOctets("BBSIM-ONU", 25),
258 "ImageHash": imageHash,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800259 },
260 Result: me.Success,
261 AttributeMask: attributeMask,
262 }
Matteo Scandolocedde462021-03-09 17:37:16 -0800263
264 omciLogger.WithFields(log.Fields{
265 "omciMessage": res,
266 "entityId": entityInstance,
267 "active": active,
268 "committed": committed,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700269 }).Trace("Reporting SoftwareImage")
Matteo Scandolocedde462021-03-09 17:37:16 -0800270
271 return res
Matteo Scandolof9d43412021-01-12 11:11:34 -0800272}
273
274func createIpHostResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
275 return &omci.GetResponse{
276 MeBasePacket: omci.MeBasePacket{
277 EntityClass: me.IpHostConfigDataClassID,
278 EntityInstance: entityInstance,
279 },
280 Attributes: me.AttributeValueMap{
281 "ManagedEntityId": 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700282 "MacAddress": ToOctets("aabbcc", 6),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800283 },
284 Result: me.Success,
285 AttributeMask: attributeMask,
286 }
287}
288
Elia Battistonac63b112022-01-12 18:40:49 +0100289func createVoipConfigDataResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
290 return &omci.GetResponse{
291 MeBasePacket: omci.MeBasePacket{
292 EntityClass: me.VoipConfigDataClassID,
293 EntityInstance: entityInstance,
294 },
295 Attributes: me.AttributeValueMap{
296 "ManagedEntityId": 0,
297 "AvailableSignallingProtocols": 1,
298 "SignallingProtocolUsed": 1,
299 "AvailableVoipConfigurationMethods": 1,
300 "VoipConfigurationMethodUsed": 1,
301 "VoipConfigurationAddressPointer": 0xFFFF,
302 "VoipConfigurationState": 0,
303 "RetrieveProfile": 0,
304 "ProfileVersion": 0,
305 },
306 Result: me.Success,
307 AttributeMask: attributeMask,
308 }
309}
310
Girish Gowdra996d81e2021-04-21 16:16:27 -0700311func createUnigResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
312 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
313 omciAdminState := 1
314 if !onuDown {
315 omciAdminState = 0
316 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800317 managedEntity, meErr := me.NewUniG(me.ParamData{
318 EntityID: entityID,
319 Attributes: me.AttributeValueMap{
320 "ManagedEntityId": entityID,
321 "Deprecated": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700322 "AdministrativeState": omciAdminState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800323 "ManagementCapability": 0,
324 "NonOmciManagementIdentifier": 1,
325 "RelayAgentOptions": 1,
326 },
327 })
328
329 if meErr.GetError() != nil {
330 omciLogger.Errorf("NewUniG %v", meErr.Error())
331 return nil
332 }
333
334 return &omci.GetResponse{
335 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800336 EntityClass: me.UniGClassID,
337 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800338 },
339 Attributes: managedEntity.GetAttributeValueMap(),
340 AttributeMask: attributeMask,
341 Result: me.Success,
342 }
343}
344
Elia Battistonac63b112022-01-12 18:40:49 +0100345func createPptpEthernetResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
Girish Gowdra996d81e2021-04-21 16:16:27 -0700346 // Valid values for oper_state are 0 (enabled) and 1 (disabled)
347 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
348 onuAdminState := 1
349 if !onuDown {
350 onuAdminState = 0
351 }
352 onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state
Matteo Scandolof9d43412021-01-12 11:11:34 -0800353 managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
354 EntityID: entityID,
355 Attributes: me.AttributeValueMap{
356 "ManagedEntityId": entityID,
357 "ExpectedType": 0,
358 "SensedType": 0,
359 "AutoDetectionConfiguration": 0,
360 "EthernetLoopbackConfiguration": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700361 "AdministrativeState": onuAdminState,
362 "OperationalState": onuOperState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800363 "ConfigurationInd": 0,
364 "MaxFrameSize": 0,
365 "DteOrDceInd": 0,
366 "PauseTime": 0,
367 "BridgedOrIpInd": 0,
368 "Arc": 0,
369 "ArcInterval": 0,
370 "PppoeFilter": 0,
371 "PowerControl": 0,
372 },
373 })
374
375 if meErr.GetError() != nil {
376 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
377 return nil
378 }
379
380 return &omci.GetResponse{
381 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800382 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
383 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800384 },
385 Attributes: managedEntity.GetAttributeValueMap(),
386 AttributeMask: attributeMask,
387 Result: me.Success,
388 }
389}
390
Elia Battistonac63b112022-01-12 18:40:49 +0100391func createPptpPotsResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
392 // Valid values for oper_state are 0 (enabled) and 1 (disabled)
393 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
394 onuAdminState := 1
395 if !onuDown {
396 onuAdminState = 0
397 }
398 onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state
399 managedEntity, meErr := me.NewPhysicalPathTerminationPointPotsUni(me.ParamData{
400 EntityID: entityID,
401 Attributes: me.AttributeValueMap{
402 "ManagedEntityId": entityID,
403 "AdministrativeState": onuAdminState,
404 "Deprecated": 0,
405 "Arc": 0,
406 "ArcInterval": 0,
407 "Impedance": 0,
408 "TransmissionPath": 0,
409 "RxGain": 0,
410 "TxGain": 0,
411 "OperationalState": onuOperState,
412 "HookState": 0,
413 "PotsHoldoverTime": 0,
414 "NominalFeedVoltage": 0,
415 "LossOfSoftswitch": 0,
416 },
417 })
418
419 if meErr.GetError() != nil {
420 omciLogger.Errorf("NewPhysicalPathTerminationPointPotsUni %v", meErr.Error())
421 return nil
422 }
423
424 return &omci.GetResponse{
425 MeBasePacket: omci.MeBasePacket{
426 EntityClass: me.PhysicalPathTerminationPointPotsUniClassID,
427 EntityInstance: entityID,
428 },
429 Attributes: managedEntity.GetAttributeValueMap(),
430 AttributeMask: attributeMask,
431 Result: me.Success,
432 }
433}
434
Girish Gowdraa539f522021-02-15 23:00:45 -0800435func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800436 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800437 EntityID: entityID,
438 Attributes: me.AttributeValueMap{
Girish Gowdraa539f522021-02-15 23:00:45 -0800439 "ManagedEntityId": entityID,
440 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
441 "ThresholdData12Id": 0,
442 "DropEvents": rand.Intn(100),
443 "Octets": rand.Intn(100),
444 "Packets": rand.Intn(100),
445 "BroadcastPackets": rand.Intn(100),
446 "MulticastPackets": rand.Intn(100),
447 "CrcErroredPackets": rand.Intn(100),
448 "UndersizePackets": rand.Intn(100),
449 "OversizePackets": rand.Intn(100),
450 "Packets64Octets": rand.Intn(100),
451 "Packets65To127Octets": rand.Intn(100),
452 "Packets128To255Octets": rand.Intn(100),
453 "Packets256To511Octets": rand.Intn(100),
454 "Packets512To1023Octets": rand.Intn(100),
455 "Packets1024To1518Octets": rand.Intn(100),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800456 },
457 })
458
459 if meErr.GetError() != nil {
Girish Gowdraa539f522021-02-15 23:00:45 -0800460 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error())
Matteo Scandolof9d43412021-01-12 11:11:34 -0800461 return nil
462 }
463
464 return &omci.GetResponse{
465 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800466 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID,
467 EntityInstance: entityID,
468 },
469 Attributes: managedEntity.GetAttributeValueMap(),
470 AttributeMask: attributeMask,
471 Result: me.Success,
472 }
473}
474
475func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800476 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{
477 EntityID: entityID,
478 Attributes: me.AttributeValueMap{
479 "ManagedEntityId": entityID,
480 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
481 "ThresholdData12Id": 0,
482 "DropEvents": rand.Intn(100),
483 "Octets": rand.Intn(100),
484 "Packets": rand.Intn(100),
485 "BroadcastPackets": rand.Intn(100),
486 "MulticastPackets": rand.Intn(100),
487 "CrcErroredPackets": rand.Intn(100),
488 "UndersizePackets": rand.Intn(100),
489 "OversizePackets": rand.Intn(100),
490 "Packets64Octets": rand.Intn(100),
491 "Packets65To127Octets": rand.Intn(100),
492 "Packets128To255Octets": rand.Intn(100),
493 "Packets256To511Octets": rand.Intn(100),
494 "Packets512To1023Octets": rand.Intn(100),
495 "Packets1024To1518Octets": rand.Intn(100),
496 },
497 })
498
499 if meErr.GetError() != nil {
500 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error())
501 return nil
502 }
503
Girish Gowdraa539f522021-02-15 23:00:45 -0800504 return &omci.GetResponse{
505 MeBasePacket: omci.MeBasePacket{
506 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID,
507 EntityInstance: entityID,
508 },
509 Attributes: managedEntity.GetAttributeValueMap(),
510 AttributeMask: attributeMask,
511 Result: me.Success,
512 }
513}
514
515func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800516 managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{
517 EntityID: entityID,
518 Attributes: me.AttributeValueMap{
519 "ManagedEntityId": entityID,
520 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
521 "ThresholdData12Id": 0,
522 "FcsErrors": rand.Intn(100),
523 "ExcessiveCollisionCounter": rand.Intn(100),
524 "LateCollisionCounter": rand.Intn(100),
525 "FramesTooLong": rand.Intn(100),
526 "BufferOverflowsOnReceive": rand.Intn(100),
527 "BufferOverflowsOnTransmit": rand.Intn(100),
528 "SingleCollisionFrameCounter": rand.Intn(100),
529 "MultipleCollisionsFrameCounter": rand.Intn(100),
530 "SqeCounter": rand.Intn(100),
531 "DeferredTransmissionCounter": rand.Intn(100),
532 "InternalMacTransmitErrorCounter": rand.Intn(100),
533 "CarrierSenseErrorCounter": rand.Intn(100),
534 "AlignmentErrorCounter": rand.Intn(100),
535 "InternalMacReceiveErrorCounter": rand.Intn(100),
536 },
537 })
538
539 if meErr.GetError() != nil {
540 omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error())
541 return nil
542 }
543
Girish Gowdraa539f522021-02-15 23:00:45 -0800544 return &omci.GetResponse{
545 MeBasePacket: omci.MeBasePacket{
546 EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID,
547 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800548 },
549 Attributes: managedEntity.GetAttributeValueMap(),
550 AttributeMask: attributeMask,
551 Result: me.Success,
552 }
553}
554
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800555func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
556 managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{
557 EntityID: entityID,
558 Attributes: me.AttributeValueMap{
559 "ManagedEntityId": entityID,
560 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
561 "ThresholdData12Id": 0,
562 "CorrectedBytes": rand.Intn(100),
563 "CorrectedCodeWords": rand.Intn(100),
564 "UncorrectableCodeWords": rand.Intn(100),
565 "TotalCodeWords": rand.Intn(100),
566 "FecSeconds": rand.Intn(100),
567 },
568 })
569
570 if meErr.GetError() != nil {
571 omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error())
572 return nil
573 }
574
575 // FEC History counter fits within single gem payload.
576 // No need of the logical we use in other Ethernet History counters or Gem Port History counters
577
578 return &omci.GetResponse{
579 MeBasePacket: omci.MeBasePacket{
580 EntityClass: me.FecPerformanceMonitoringHistoryDataClassID,
581 EntityInstance: entityID,
582 },
583 Attributes: managedEntity.GetAttributeValueMap(),
584 AttributeMask: attributeMask,
585 Result: me.Success,
586 }
587}
588
589func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse {
590 managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{
591 EntityID: entityID,
592 Attributes: me.AttributeValueMap{
593 "ManagedEntityId": entityID,
594 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
595 "ThresholdData12Id": 0,
596 "TransmittedGemFrames": rand.Intn(100),
597 "ReceivedGemFrames": rand.Intn(100),
598 "ReceivedPayloadBytes": rand.Intn(100),
599 "TransmittedPayloadBytes": rand.Intn(100),
600 "EncryptionKeyErrors": rand.Intn(100),
601 },
602 })
603
604 if meErr.GetError() != nil {
605 omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error())
606 return nil
607 }
608
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800609 return &omci.GetResponse{
610 MeBasePacket: omci.MeBasePacket{
611 EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID,
612 EntityInstance: entityID,
613 },
614 Attributes: managedEntity.GetAttributeValueMap(),
615 AttributeMask: attributeMask,
616 Result: me.Success,
617 }
618}
619
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800620func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800621 managedEntity, meErr := me.NewOnuData(me.ParamData{
622 EntityID: entityID,
623 Attributes: me.AttributeValueMap{
624 "ManagedEntityId": entityID,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800625 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800626 },
627 })
628
629 if meErr.GetError() != nil {
630 omciLogger.Errorf("NewOnuData %v", meErr.Error())
631 return nil
632 }
633
634 return &omci.GetResponse{
635 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800636 EntityClass: me.OnuDataClassID,
637 EntityInstance: entityID,
638 },
639 Attributes: managedEntity.GetAttributeValueMap(),
640 AttributeMask: attributeMask,
641 Result: me.Success,
642 }
643}
644
645func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
646 managedEntity, meErr := me.NewAniG(me.ParamData{
647 EntityID: entityID,
648 Attributes: me.AttributeValueMap{
649 "ManagedEntityId": entityID,
650 "SrIndication": 0,
651 "TotalTcontNumber": 0,
652 "GemBlockLength": 0,
653 "PiggybackDbaReporting": 0,
654 "Deprecated": 0,
655 "SignalFailThreshold": 0,
656 "SignalDegradeThreshold": 0,
657 "Arc": 0,
658 "ArcInterval": 0,
659 "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
660 "LowerOpticalThreshold": 0,
661 "UpperOpticalThreshold": 0,
662 "OnuResponseTime": 0,
663 "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
664 "LowerTransmitPowerThreshold": 0,
665 "UpperTransmitPowerThreshold": 0,
666 },
667 })
668
669 if meErr.GetError() != nil {
670 omciLogger.Errorf("NewAniG %v", meErr.Error())
671 return nil
672 }
673
674 return &omci.GetResponse{
675 MeBasePacket: omci.MeBasePacket{
676 EntityClass: me.AniGClassID,
677 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800678 },
679 Attributes: managedEntity.GetAttributeValueMap(),
680 AttributeMask: attributeMask,
681 Result: me.Success,
682 }
683}
684
Himani Chawla6bd190a2021-07-09 15:31:01 +0530685func createEthernetFrameExtendedPmGetResponse(meClass me.ClassID, attributeMask uint16, entityID uint16) *omci.GetResponse {
686
687 callback := me.NewEthernetFrameExtendedPm
688 if meClass != me.EthernetFrameExtendedPmClassID {
689 callback = me.NewEthernetFrameExtendedPm64Bit
690 }
691 managedEntity, meErr := callback(me.ParamData{
692 EntityID: entityID,
693 Attributes: me.AttributeValueMap{
694 "ManagedEntityId": entityID,
695 "DropEvents": rand.Intn(100),
696 "Octets": rand.Intn(100),
697 "Frames": rand.Intn(100),
698 "BroadcastFrames": rand.Intn(100),
699 "MulticastFrames": rand.Intn(100),
700 "CrcErroredFrames": rand.Intn(100),
701 "UndersizeFrames": rand.Intn(100),
702 "OversizeFrames": rand.Intn(100),
703 "Frames64Octets": rand.Intn(100),
704 "Frames65To127Octets": rand.Intn(100),
705 "Frames128To255Octets": rand.Intn(100),
706 "Frames256To511Octets": rand.Intn(100),
707 "Frames512To1023Octets": rand.Intn(100),
708 "Frames1024To1518Octets": rand.Intn(100),
709 },
710 })
711
712 if meErr.GetError() != nil {
713 omciLogger.Errorf("NewEthernetFrameExtendedPm %v", meErr.Error())
714 return nil
715 }
716
717 return &omci.GetResponse{
718 MeBasePacket: omci.MeBasePacket{
719 EntityClass: meClass,
720 EntityInstance: entityID,
721 },
722 Attributes: managedEntity.GetAttributeValueMap(),
723 AttributeMask: attributeMask,
724 Result: me.Success,
725 }
726}
727
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700728func ToOctets(str string, size int) []byte {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800729 asciiBytes := []byte(str)
730
731 if len(asciiBytes) < size {
732 missing := size - len(asciiBytes)
733 for i := 0; i < missing; i++ {
734 asciiBytes = append(asciiBytes, []byte{0x00}[0])
735 }
736 }
737 return asciiBytes
738}