blob: a8fc6d7e75208d158a3cac93f0d3e067aeb4e176 [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"
Andrea Campanella10426e22021-10-15 17:58:04 +020024 "github.com/opencord/omci-lib-go/v2"
25 me "github.com/opencord/omci-lib-go/v2/generated"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000026 "github.com/opencord/voltha-protos/v5/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 Scandoloc00e97a2021-05-27 11:45:27 -070048func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8,
49 activeImageEntityId uint16, committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string,
50 committedImageVersion string, onuDown bool) ([]byte, error) {
Matteo Scandolof9d43412021-01-12 11:11:34 -080051
52 msgObj, err := ParseGetRequest(omciPkt)
53
54 if err != nil {
55 return nil, err
56 }
57
58 omciLogger.WithFields(log.Fields{
59 "EntityClass": msgObj.EntityClass,
60 "EntityInstance": msgObj.EntityInstance,
61 "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask),
Matteo Scandolo992a23e2021-02-04 15:35:04 -080062 }).Trace("received-omci-get-request")
Matteo Scandolof9d43412021-01-12 11:11:34 -080063
64 var response *omci.GetResponse
65 switch msgObj.EntityClass {
66 case me.Onu2GClassID:
67 response = createOnu2gResponse(msgObj.AttributeMask, msgObj.EntityInstance)
68 case me.OnuGClassID:
Matteo Scandolo5863f002021-02-08 08:08:14 -080069 response = createOnugResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuSn)
Matteo Scandolof9d43412021-01-12 11:11:34 -080070 case me.SoftwareImageClassID:
Matteo Scandoloc00e97a2021-05-27 11:45:27 -070071 response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance,
72 activeImageEntityId, committedImageEntityId, standbyImageVersion, activeImageVersion, committedImageVersion)
Matteo Scandolof9d43412021-01-12 11:11:34 -080073 case me.IpHostConfigDataClassID:
74 response = createIpHostResponse(msgObj.AttributeMask, msgObj.EntityInstance)
75 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:
Girish Gowdra996d81e2021-04-21 16:16:27 -070078 response = createPptpResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown)
Matteo Scandolof9d43412021-01-12 11:11:34 -080079 case me.AniGClassID:
80 response = createAnigResponse(msgObj.AttributeMask, msgObj.EntityInstance)
81 case me.OnuDataClassID:
Matteo Scandolo992a23e2021-02-04 15:35:04 -080082 response = createOnuDataResponse(msgObj.AttributeMask, msgObj.EntityInstance, mds)
Girish Gowdraa539f522021-02-15 23:00:45 -080083 case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID:
84 response = createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance)
85 case me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID:
86 response = createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance)
87 case me.EthernetPerformanceMonitoringHistoryDataClassID:
88 response = createEthernetPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
Girish Gowdra6d9a1a42021-03-05 16:07:15 -080089 case me.FecPerformanceMonitoringHistoryDataClassID:
90 response = createFecPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance)
91 case me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID:
92 response = createGemPortNetworkCtpPerformanceMonitoringHistoryData(msgObj.AttributeMask, msgObj.EntityInstance)
Himani Chawla6bd190a2021-07-09 15:31:01 +053093 case me.EthernetFrameExtendedPmClassID,
94 me.EthernetFrameExtendedPm64BitClassID:
95 response = createEthernetFrameExtendedPmGetResponse(msgObj.EntityClass, msgObj.AttributeMask, msgObj.EntityInstance)
Matteo Scandolof9d43412021-01-12 11:11:34 -080096 default:
97 omciLogger.WithFields(log.Fields{
98 "EntityClass": msgObj.EntityClass,
99 "EntityInstance": msgObj.EntityInstance,
100 "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask),
101 }).Warnf("do-not-know-how-to-handle-get-request-for-me-class")
102 return nil, nil
103 }
104
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800105 pkt, err := Serialize(omci.GetResponseType, response, omciMsg.TransactionID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800106 if err != nil {
107 omciLogger.WithFields(log.Fields{
108 "Err": err,
109 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
Matteo Scandolo78d5ee12021-04-14 11:11:32 -0700110 }).Error("cannot-Serialize-GetResponse")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800111 return nil, err
112 }
113
114 log.WithFields(log.Fields{
115 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
116 "pkt": hex.EncodeToString(pkt),
117 }).Trace("omci-get-response")
118
119 return pkt, nil
120}
121
122func createOnu2gResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
123
124 managedEntity, meErr := me.NewOnu2G(me.ParamData{
125 EntityID: entityID,
126 Attributes: me.AttributeValueMap{
127 "ManagedEntityId": entityID,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700128 "EquipmentId": ToOctets("12345123451234512345", 20),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800129 "OpticalNetworkUnitManagementAndControlChannelOmccVersion": 180,
130 "VendorProductCode": 0,
131 "SecurityCapability": 1,
132 "SecurityMode": 1,
133 "TotalPriorityQueueNumber": 1,
134 "TotalTrafficSchedulerNumber": 1,
135 "Deprecated": 1,
136 "TotalGemPortIdNumber": 32,
137 "Sysuptime": 319389947, // NOTE need to be smarter?
138 "ConnectivityCapability": 127,
139 "CurrentConnectivityMode": 5,
140 "QualityOfServiceQosConfigurationFlexibility": 48,
141 "PriorityQueueScaleFactor": 1,
142 },
143 })
144
145 if meErr.GetError() != nil {
146 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
147 return nil
148 }
149
150 return &omci.GetResponse{
151 MeBasePacket: omci.MeBasePacket{
152 EntityClass: me.Onu2GClassID,
153 },
154 Attributes: managedEntity.GetAttributeValueMap(),
155 AttributeMask: attributeMask,
156 Result: me.Success,
157 }
158}
159
Matteo Scandolo5863f002021-02-08 08:08:14 -0800160func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse {
161
162 managedEntity, meErr := me.NewOnuG(me.ParamData{
163 EntityID: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800164 Attributes: me.AttributeValueMap{
165 "ManagedEntityId": entityID,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700166 "VendorId": ToOctets("BBSM", 4),
167 "Version": ToOctets("v0.0.1", 14),
Matteo Scandolo5863f002021-02-08 08:08:14 -0800168 "SerialNumber": append(onuSn.VendorId, onuSn.VendorSpecific...),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800169 "TrafficManagementOption": 0,
170 "Deprecated": 0,
171 "BatteryBackup": 0,
172 "AdministrativeState": 0,
173 "OperationalState": 0,
174 "OnuSurvivalTime": 10,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700175 "LogicalOnuId": ToOctets("BBSM", 24),
176 "LogicalPassword": ToOctets("BBSM", 12),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800177 "CredentialsStatus": 0,
178 "ExtendedTcLayerOptions": 0,
179 },
Matteo Scandolo5863f002021-02-08 08:08:14 -0800180 })
181
182 if meErr.GetError() != nil {
183 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
184 return nil
Matteo Scandolof9d43412021-01-12 11:11:34 -0800185 }
Matteo Scandolo5863f002021-02-08 08:08:14 -0800186
187 return &omci.GetResponse{
188 MeBasePacket: omci.MeBasePacket{
189 EntityClass: me.OnuGClassID,
190 },
191 Attributes: managedEntity.GetAttributeValueMap(),
192 AttributeMask: attributeMask,
193 Result: me.Success,
194 }
195
196 //return &omci.GetResponse{
197 // MeBasePacket: omci.MeBasePacket{
198 // EntityClass: me.OnuGClassID,
199 // EntityInstance: entityID,
200 // },
201 // Attributes: me.AttributeValueMap{
202 //
203 // },
204 // Result: me.Success,
205 // AttributeMask: attributeMask,
206 //}
Matteo Scandolof9d43412021-01-12 11:11:34 -0800207}
208
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700209func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16, activeImageEntityId uint16,
210 committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string, committedImageVersion string) *omci.GetResponse {
Matteo Scandolocedde462021-03-09 17:37:16 -0800211
212 omciLogger.WithFields(log.Fields{
213 "EntityInstance": entityInstance,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700214 "AttributeMask": attributeMask,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700215 }).Trace("received-get-software-image-request")
Matteo Scandolocedde462021-03-09 17:37:16 -0800216
217 // Only one image can be active and committed
218 committed := 0
219 active := 0
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700220 version := standbyImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -0800221 if entityInstance == activeImageEntityId {
222 active = 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700223 version = activeImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -0800224 }
225 if entityInstance == committedImageEntityId {
226 committed = 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700227 version = committedImageVersion
228 }
229
230 imageHash, err := hex.DecodeString(hex.EncodeToString([]byte(version)))
231 if err != nil {
232 omciLogger.WithFields(log.Fields{
233 "entityId": entityInstance,
234 "active": active,
235 "committed": committed,
236 "err": err,
237 }).Error("cannot-generate-image-hash")
Matteo Scandolocedde462021-03-09 17:37:16 -0800238 }
239
Matteo Scandolof9d43412021-01-12 11:11:34 -0800240 // 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 -0800241 res := &omci.GetResponse{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800242 MeBasePacket: omci.MeBasePacket{
243 EntityClass: me.SoftwareImageClassID,
244 EntityInstance: entityInstance,
245 },
246 Attributes: me.AttributeValueMap{
247 "ManagedEntityId": 0,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700248 "Version": ToOctets(version, 14),
Matteo Scandolocedde462021-03-09 17:37:16 -0800249 "IsCommitted": committed,
250 "IsActive": active,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800251 "IsValid": 1,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700252 "ProductCode": ToOctets("BBSIM-ONU", 25),
253 "ImageHash": imageHash,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800254 },
255 Result: me.Success,
256 AttributeMask: attributeMask,
257 }
Matteo Scandolocedde462021-03-09 17:37:16 -0800258
259 omciLogger.WithFields(log.Fields{
260 "omciMessage": res,
261 "entityId": entityInstance,
262 "active": active,
263 "committed": committed,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700264 }).Trace("Reporting SoftwareImage")
Matteo Scandolocedde462021-03-09 17:37:16 -0800265
266 return res
Matteo Scandolof9d43412021-01-12 11:11:34 -0800267}
268
269func createIpHostResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
270 return &omci.GetResponse{
271 MeBasePacket: omci.MeBasePacket{
272 EntityClass: me.IpHostConfigDataClassID,
273 EntityInstance: entityInstance,
274 },
275 Attributes: me.AttributeValueMap{
276 "ManagedEntityId": 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700277 "MacAddress": ToOctets("aabbcc", 6),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800278 },
279 Result: me.Success,
280 AttributeMask: attributeMask,
281 }
282}
283
Girish Gowdra996d81e2021-04-21 16:16:27 -0700284func createUnigResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
285 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
286 omciAdminState := 1
287 if !onuDown {
288 omciAdminState = 0
289 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800290 managedEntity, meErr := me.NewUniG(me.ParamData{
291 EntityID: entityID,
292 Attributes: me.AttributeValueMap{
293 "ManagedEntityId": entityID,
294 "Deprecated": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700295 "AdministrativeState": omciAdminState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800296 "ManagementCapability": 0,
297 "NonOmciManagementIdentifier": 1,
298 "RelayAgentOptions": 1,
299 },
300 })
301
302 if meErr.GetError() != nil {
303 omciLogger.Errorf("NewUniG %v", meErr.Error())
304 return nil
305 }
306
307 return &omci.GetResponse{
308 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800309 EntityClass: me.UniGClassID,
310 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800311 },
312 Attributes: managedEntity.GetAttributeValueMap(),
313 AttributeMask: attributeMask,
314 Result: me.Success,
315 }
316}
317
Girish Gowdra996d81e2021-04-21 16:16:27 -0700318func createPptpResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
319 // Valid values for oper_state are 0 (enabled) and 1 (disabled)
320 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
321 onuAdminState := 1
322 if !onuDown {
323 onuAdminState = 0
324 }
325 onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state
Matteo Scandolof9d43412021-01-12 11:11:34 -0800326 managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
327 EntityID: entityID,
328 Attributes: me.AttributeValueMap{
329 "ManagedEntityId": entityID,
330 "ExpectedType": 0,
331 "SensedType": 0,
332 "AutoDetectionConfiguration": 0,
333 "EthernetLoopbackConfiguration": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700334 "AdministrativeState": onuAdminState,
335 "OperationalState": onuOperState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800336 "ConfigurationInd": 0,
337 "MaxFrameSize": 0,
338 "DteOrDceInd": 0,
339 "PauseTime": 0,
340 "BridgedOrIpInd": 0,
341 "Arc": 0,
342 "ArcInterval": 0,
343 "PppoeFilter": 0,
344 "PowerControl": 0,
345 },
346 })
347
348 if meErr.GetError() != nil {
349 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
350 return nil
351 }
352
353 return &omci.GetResponse{
354 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800355 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
356 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800357 },
358 Attributes: managedEntity.GetAttributeValueMap(),
359 AttributeMask: attributeMask,
360 Result: me.Success,
361 }
362}
363
Girish Gowdraa539f522021-02-15 23:00:45 -0800364func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800365 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800366 EntityID: entityID,
367 Attributes: me.AttributeValueMap{
Girish Gowdraa539f522021-02-15 23:00:45 -0800368 "ManagedEntityId": entityID,
369 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
370 "ThresholdData12Id": 0,
371 "DropEvents": rand.Intn(100),
372 "Octets": rand.Intn(100),
373 "Packets": rand.Intn(100),
374 "BroadcastPackets": rand.Intn(100),
375 "MulticastPackets": rand.Intn(100),
376 "CrcErroredPackets": rand.Intn(100),
377 "UndersizePackets": rand.Intn(100),
378 "OversizePackets": rand.Intn(100),
379 "Packets64Octets": rand.Intn(100),
380 "Packets65To127Octets": rand.Intn(100),
381 "Packets128To255Octets": rand.Intn(100),
382 "Packets256To511Octets": rand.Intn(100),
383 "Packets512To1023Octets": rand.Intn(100),
384 "Packets1024To1518Octets": rand.Intn(100),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800385 },
386 })
387
388 if meErr.GetError() != nil {
Girish Gowdraa539f522021-02-15 23:00:45 -0800389 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error())
Matteo Scandolof9d43412021-01-12 11:11:34 -0800390 return nil
391 }
392
393 return &omci.GetResponse{
394 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800395 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID,
396 EntityInstance: entityID,
397 },
398 Attributes: managedEntity.GetAttributeValueMap(),
399 AttributeMask: attributeMask,
400 Result: me.Success,
401 }
402}
403
404func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800405 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{
406 EntityID: entityID,
407 Attributes: me.AttributeValueMap{
408 "ManagedEntityId": entityID,
409 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
410 "ThresholdData12Id": 0,
411 "DropEvents": rand.Intn(100),
412 "Octets": rand.Intn(100),
413 "Packets": rand.Intn(100),
414 "BroadcastPackets": rand.Intn(100),
415 "MulticastPackets": rand.Intn(100),
416 "CrcErroredPackets": rand.Intn(100),
417 "UndersizePackets": rand.Intn(100),
418 "OversizePackets": rand.Intn(100),
419 "Packets64Octets": rand.Intn(100),
420 "Packets65To127Octets": rand.Intn(100),
421 "Packets128To255Octets": rand.Intn(100),
422 "Packets256To511Octets": rand.Intn(100),
423 "Packets512To1023Octets": rand.Intn(100),
424 "Packets1024To1518Octets": rand.Intn(100),
425 },
426 })
427
428 if meErr.GetError() != nil {
429 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error())
430 return nil
431 }
432
Girish Gowdraa539f522021-02-15 23:00:45 -0800433 return &omci.GetResponse{
434 MeBasePacket: omci.MeBasePacket{
435 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID,
436 EntityInstance: entityID,
437 },
438 Attributes: managedEntity.GetAttributeValueMap(),
439 AttributeMask: attributeMask,
440 Result: me.Success,
441 }
442}
443
444func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800445 managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{
446 EntityID: entityID,
447 Attributes: me.AttributeValueMap{
448 "ManagedEntityId": entityID,
449 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
450 "ThresholdData12Id": 0,
451 "FcsErrors": rand.Intn(100),
452 "ExcessiveCollisionCounter": rand.Intn(100),
453 "LateCollisionCounter": rand.Intn(100),
454 "FramesTooLong": rand.Intn(100),
455 "BufferOverflowsOnReceive": rand.Intn(100),
456 "BufferOverflowsOnTransmit": rand.Intn(100),
457 "SingleCollisionFrameCounter": rand.Intn(100),
458 "MultipleCollisionsFrameCounter": rand.Intn(100),
459 "SqeCounter": rand.Intn(100),
460 "DeferredTransmissionCounter": rand.Intn(100),
461 "InternalMacTransmitErrorCounter": rand.Intn(100),
462 "CarrierSenseErrorCounter": rand.Intn(100),
463 "AlignmentErrorCounter": rand.Intn(100),
464 "InternalMacReceiveErrorCounter": rand.Intn(100),
465 },
466 })
467
468 if meErr.GetError() != nil {
469 omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error())
470 return nil
471 }
472
Girish Gowdraa539f522021-02-15 23:00:45 -0800473 return &omci.GetResponse{
474 MeBasePacket: omci.MeBasePacket{
475 EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID,
476 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800477 },
478 Attributes: managedEntity.GetAttributeValueMap(),
479 AttributeMask: attributeMask,
480 Result: me.Success,
481 }
482}
483
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800484func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
485 managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{
486 EntityID: entityID,
487 Attributes: me.AttributeValueMap{
488 "ManagedEntityId": entityID,
489 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
490 "ThresholdData12Id": 0,
491 "CorrectedBytes": rand.Intn(100),
492 "CorrectedCodeWords": rand.Intn(100),
493 "UncorrectableCodeWords": rand.Intn(100),
494 "TotalCodeWords": rand.Intn(100),
495 "FecSeconds": rand.Intn(100),
496 },
497 })
498
499 if meErr.GetError() != nil {
500 omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error())
501 return nil
502 }
503
504 // FEC History counter fits within single gem payload.
505 // No need of the logical we use in other Ethernet History counters or Gem Port History counters
506
507 return &omci.GetResponse{
508 MeBasePacket: omci.MeBasePacket{
509 EntityClass: me.FecPerformanceMonitoringHistoryDataClassID,
510 EntityInstance: entityID,
511 },
512 Attributes: managedEntity.GetAttributeValueMap(),
513 AttributeMask: attributeMask,
514 Result: me.Success,
515 }
516}
517
518func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse {
519 managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{
520 EntityID: entityID,
521 Attributes: me.AttributeValueMap{
522 "ManagedEntityId": entityID,
523 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
524 "ThresholdData12Id": 0,
525 "TransmittedGemFrames": rand.Intn(100),
526 "ReceivedGemFrames": rand.Intn(100),
527 "ReceivedPayloadBytes": rand.Intn(100),
528 "TransmittedPayloadBytes": rand.Intn(100),
529 "EncryptionKeyErrors": rand.Intn(100),
530 },
531 })
532
533 if meErr.GetError() != nil {
534 omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error())
535 return nil
536 }
537
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800538 return &omci.GetResponse{
539 MeBasePacket: omci.MeBasePacket{
540 EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID,
541 EntityInstance: entityID,
542 },
543 Attributes: managedEntity.GetAttributeValueMap(),
544 AttributeMask: attributeMask,
545 Result: me.Success,
546 }
547}
548
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800549func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800550 managedEntity, meErr := me.NewOnuData(me.ParamData{
551 EntityID: entityID,
552 Attributes: me.AttributeValueMap{
553 "ManagedEntityId": entityID,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800554 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800555 },
556 })
557
558 if meErr.GetError() != nil {
559 omciLogger.Errorf("NewOnuData %v", meErr.Error())
560 return nil
561 }
562
563 return &omci.GetResponse{
564 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800565 EntityClass: me.OnuDataClassID,
566 EntityInstance: entityID,
567 },
568 Attributes: managedEntity.GetAttributeValueMap(),
569 AttributeMask: attributeMask,
570 Result: me.Success,
571 }
572}
573
574func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
575 managedEntity, meErr := me.NewAniG(me.ParamData{
576 EntityID: entityID,
577 Attributes: me.AttributeValueMap{
578 "ManagedEntityId": entityID,
579 "SrIndication": 0,
580 "TotalTcontNumber": 0,
581 "GemBlockLength": 0,
582 "PiggybackDbaReporting": 0,
583 "Deprecated": 0,
584 "SignalFailThreshold": 0,
585 "SignalDegradeThreshold": 0,
586 "Arc": 0,
587 "ArcInterval": 0,
588 "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
589 "LowerOpticalThreshold": 0,
590 "UpperOpticalThreshold": 0,
591 "OnuResponseTime": 0,
592 "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
593 "LowerTransmitPowerThreshold": 0,
594 "UpperTransmitPowerThreshold": 0,
595 },
596 })
597
598 if meErr.GetError() != nil {
599 omciLogger.Errorf("NewAniG %v", meErr.Error())
600 return nil
601 }
602
603 return &omci.GetResponse{
604 MeBasePacket: omci.MeBasePacket{
605 EntityClass: me.AniGClassID,
606 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800607 },
608 Attributes: managedEntity.GetAttributeValueMap(),
609 AttributeMask: attributeMask,
610 Result: me.Success,
611 }
612}
613
Himani Chawla6bd190a2021-07-09 15:31:01 +0530614func createEthernetFrameExtendedPmGetResponse(meClass me.ClassID, attributeMask uint16, entityID uint16) *omci.GetResponse {
615
616 callback := me.NewEthernetFrameExtendedPm
617 if meClass != me.EthernetFrameExtendedPmClassID {
618 callback = me.NewEthernetFrameExtendedPm64Bit
619 }
620 managedEntity, meErr := callback(me.ParamData{
621 EntityID: entityID,
622 Attributes: me.AttributeValueMap{
623 "ManagedEntityId": entityID,
624 "DropEvents": rand.Intn(100),
625 "Octets": rand.Intn(100),
626 "Frames": rand.Intn(100),
627 "BroadcastFrames": rand.Intn(100),
628 "MulticastFrames": rand.Intn(100),
629 "CrcErroredFrames": rand.Intn(100),
630 "UndersizeFrames": rand.Intn(100),
631 "OversizeFrames": rand.Intn(100),
632 "Frames64Octets": rand.Intn(100),
633 "Frames65To127Octets": rand.Intn(100),
634 "Frames128To255Octets": rand.Intn(100),
635 "Frames256To511Octets": rand.Intn(100),
636 "Frames512To1023Octets": rand.Intn(100),
637 "Frames1024To1518Octets": rand.Intn(100),
638 },
639 })
640
641 if meErr.GetError() != nil {
642 omciLogger.Errorf("NewEthernetFrameExtendedPm %v", meErr.Error())
643 return nil
644 }
645
646 return &omci.GetResponse{
647 MeBasePacket: omci.MeBasePacket{
648 EntityClass: meClass,
649 EntityInstance: entityID,
650 },
651 Attributes: managedEntity.GetAttributeValueMap(),
652 AttributeMask: attributeMask,
653 Result: me.Success,
654 }
655}
656
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700657func ToOctets(str string, size int) []byte {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800658 asciiBytes := []byte(str)
659
660 if len(asciiBytes) < size {
661 missing := size - len(asciiBytes)
662 for i := 0; i < missing; i++ {
663 asciiBytes = append(asciiBytes, []byte{0x00}[0])
664 }
665 }
666 return asciiBytes
667}