blob: e50c47a25b2148d07643bf1f8d4fbf4778abfb77 [file] [log] [blame]
Matteo Scandolof9d43412021-01-12 11:11:34 -08001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package omci
18
19import (
20 "encoding/hex"
21 "errors"
22 "fmt"
23 "github.com/google/gopacket"
24 "github.com/opencord/omci-lib-go"
25 me "github.com/opencord/omci-lib-go/generated"
Matteo Scandolo5863f002021-02-08 08:08:14 -080026 "github.com/opencord/voltha-protos/v4/go/openolt"
Matteo Scandolof9d43412021-01-12 11:11:34 -080027 log "github.com/sirupsen/logrus"
Girish Gowdraa539f522021-02-15 23:00:45 -080028 "math/rand"
Matteo Scandolof9d43412021-01-12 11:11:34 -080029 "strconv"
30)
31
32func ParseGetRequest(omciPkt gopacket.Packet) (*omci.GetRequest, error) {
33 msgLayer := omciPkt.Layer(omci.LayerTypeGetRequest)
34 if msgLayer == nil {
35 err := "omci Msg layer could not be detected for LayerTypeGetRequest"
36 omciLogger.Error(err)
37 return nil, errors.New(err)
38 }
39 msgObj, msgOk := msgLayer.(*omci.GetRequest)
40 if !msgOk {
41 err := "omci Msg layer could not be assigned for LayerTypeGetRequest"
42 omciLogger.Error(err)
43 return nil, errors.New(err)
44 }
45 return msgObj, nil
46}
47
Matteo 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)
Matteo Scandolof9d43412021-01-12 11:11:34 -080093 default:
94 omciLogger.WithFields(log.Fields{
95 "EntityClass": msgObj.EntityClass,
96 "EntityInstance": msgObj.EntityInstance,
97 "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask),
98 }).Warnf("do-not-know-how-to-handle-get-request-for-me-class")
99 return nil, nil
100 }
101
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800102 pkt, err := Serialize(omci.GetResponseType, response, omciMsg.TransactionID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800103 if err != nil {
104 omciLogger.WithFields(log.Fields{
105 "Err": err,
106 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
Matteo Scandolo78d5ee12021-04-14 11:11:32 -0700107 }).Error("cannot-Serialize-GetResponse")
Matteo Scandolof9d43412021-01-12 11:11:34 -0800108 return nil, err
109 }
110
111 log.WithFields(log.Fields{
112 "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
113 "pkt": hex.EncodeToString(pkt),
114 }).Trace("omci-get-response")
115
116 return pkt, nil
117}
118
119func createOnu2gResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
120
121 managedEntity, meErr := me.NewOnu2G(me.ParamData{
122 EntityID: entityID,
123 Attributes: me.AttributeValueMap{
124 "ManagedEntityId": entityID,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700125 "EquipmentId": ToOctets("12345123451234512345", 20),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800126 "OpticalNetworkUnitManagementAndControlChannelOmccVersion": 180,
127 "VendorProductCode": 0,
128 "SecurityCapability": 1,
129 "SecurityMode": 1,
130 "TotalPriorityQueueNumber": 1,
131 "TotalTrafficSchedulerNumber": 1,
132 "Deprecated": 1,
133 "TotalGemPortIdNumber": 32,
134 "Sysuptime": 319389947, // NOTE need to be smarter?
135 "ConnectivityCapability": 127,
136 "CurrentConnectivityMode": 5,
137 "QualityOfServiceQosConfigurationFlexibility": 48,
138 "PriorityQueueScaleFactor": 1,
139 },
140 })
141
142 if meErr.GetError() != nil {
143 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
144 return nil
145 }
146
147 return &omci.GetResponse{
148 MeBasePacket: omci.MeBasePacket{
149 EntityClass: me.Onu2GClassID,
150 },
151 Attributes: managedEntity.GetAttributeValueMap(),
152 AttributeMask: attributeMask,
153 Result: me.Success,
154 }
155}
156
Matteo Scandolo5863f002021-02-08 08:08:14 -0800157func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse {
158
159 managedEntity, meErr := me.NewOnuG(me.ParamData{
160 EntityID: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800161 Attributes: me.AttributeValueMap{
162 "ManagedEntityId": entityID,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700163 "VendorId": ToOctets("BBSM", 4),
164 "Version": ToOctets("v0.0.1", 14),
Matteo Scandolo5863f002021-02-08 08:08:14 -0800165 "SerialNumber": append(onuSn.VendorId, onuSn.VendorSpecific...),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800166 "TrafficManagementOption": 0,
167 "Deprecated": 0,
168 "BatteryBackup": 0,
169 "AdministrativeState": 0,
170 "OperationalState": 0,
171 "OnuSurvivalTime": 10,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700172 "LogicalOnuId": ToOctets("BBSM", 24),
173 "LogicalPassword": ToOctets("BBSM", 12),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800174 "CredentialsStatus": 0,
175 "ExtendedTcLayerOptions": 0,
176 },
Matteo Scandolo5863f002021-02-08 08:08:14 -0800177 })
178
179 if meErr.GetError() != nil {
180 omciLogger.Errorf("NewOnu2G %v", meErr.Error())
181 return nil
Matteo Scandolof9d43412021-01-12 11:11:34 -0800182 }
Matteo Scandolo5863f002021-02-08 08:08:14 -0800183
184 return &omci.GetResponse{
185 MeBasePacket: omci.MeBasePacket{
186 EntityClass: me.OnuGClassID,
187 },
188 Attributes: managedEntity.GetAttributeValueMap(),
189 AttributeMask: attributeMask,
190 Result: me.Success,
191 }
192
193 //return &omci.GetResponse{
194 // MeBasePacket: omci.MeBasePacket{
195 // EntityClass: me.OnuGClassID,
196 // EntityInstance: entityID,
197 // },
198 // Attributes: me.AttributeValueMap{
199 //
200 // },
201 // Result: me.Success,
202 // AttributeMask: attributeMask,
203 //}
Matteo Scandolof9d43412021-01-12 11:11:34 -0800204}
205
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700206func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16, activeImageEntityId uint16,
207 committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string, committedImageVersion string) *omci.GetResponse {
Matteo Scandolocedde462021-03-09 17:37:16 -0800208
209 omciLogger.WithFields(log.Fields{
210 "EntityInstance": entityInstance,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700211 "AttributeMask": attributeMask,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700212 }).Trace("received-get-software-image-request")
Matteo Scandolocedde462021-03-09 17:37:16 -0800213
214 // Only one image can be active and committed
215 committed := 0
216 active := 0
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700217 version := standbyImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -0800218 if entityInstance == activeImageEntityId {
219 active = 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700220 version = activeImageVersion
Matteo Scandolocedde462021-03-09 17:37:16 -0800221 }
222 if entityInstance == committedImageEntityId {
223 committed = 1
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700224 version = committedImageVersion
225 }
226
227 imageHash, err := hex.DecodeString(hex.EncodeToString([]byte(version)))
228 if err != nil {
229 omciLogger.WithFields(log.Fields{
230 "entityId": entityInstance,
231 "active": active,
232 "committed": committed,
233 "err": err,
234 }).Error("cannot-generate-image-hash")
Matteo Scandolocedde462021-03-09 17:37:16 -0800235 }
236
Matteo Scandolof9d43412021-01-12 11:11:34 -0800237 // 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 -0800238 res := &omci.GetResponse{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800239 MeBasePacket: omci.MeBasePacket{
240 EntityClass: me.SoftwareImageClassID,
241 EntityInstance: entityInstance,
242 },
243 Attributes: me.AttributeValueMap{
244 "ManagedEntityId": 0,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700245 "Version": ToOctets(version, 14),
Matteo Scandolocedde462021-03-09 17:37:16 -0800246 "IsCommitted": committed,
247 "IsActive": active,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800248 "IsValid": 1,
Matteo Scandoloc00e97a2021-05-27 11:45:27 -0700249 "ProductCode": ToOctets("BBSIM-ONU", 25),
250 "ImageHash": imageHash,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800251 },
252 Result: me.Success,
253 AttributeMask: attributeMask,
254 }
Matteo Scandolocedde462021-03-09 17:37:16 -0800255
256 omciLogger.WithFields(log.Fields{
257 "omciMessage": res,
258 "entityId": entityInstance,
259 "active": active,
260 "committed": committed,
Matteo Scandolo21195d62021-04-07 14:31:23 -0700261 }).Trace("Reporting SoftwareImage")
Matteo Scandolocedde462021-03-09 17:37:16 -0800262
263 return res
Matteo Scandolof9d43412021-01-12 11:11:34 -0800264}
265
266func createIpHostResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse {
267 return &omci.GetResponse{
268 MeBasePacket: omci.MeBasePacket{
269 EntityClass: me.IpHostConfigDataClassID,
270 EntityInstance: entityInstance,
271 },
272 Attributes: me.AttributeValueMap{
273 "ManagedEntityId": 0,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700274 "MacAddress": ToOctets("aabbcc", 6),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800275 },
276 Result: me.Success,
277 AttributeMask: attributeMask,
278 }
279}
280
Girish Gowdra996d81e2021-04-21 16:16:27 -0700281func createUnigResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
282 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
283 omciAdminState := 1
284 if !onuDown {
285 omciAdminState = 0
286 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800287 managedEntity, meErr := me.NewUniG(me.ParamData{
288 EntityID: entityID,
289 Attributes: me.AttributeValueMap{
290 "ManagedEntityId": entityID,
291 "Deprecated": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700292 "AdministrativeState": omciAdminState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800293 "ManagementCapability": 0,
294 "NonOmciManagementIdentifier": 1,
295 "RelayAgentOptions": 1,
296 },
297 })
298
299 if meErr.GetError() != nil {
300 omciLogger.Errorf("NewUniG %v", meErr.Error())
301 return nil
302 }
303
304 return &omci.GetResponse{
305 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800306 EntityClass: me.UniGClassID,
307 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800308 },
309 Attributes: managedEntity.GetAttributeValueMap(),
310 AttributeMask: attributeMask,
311 Result: me.Success,
312 }
313}
314
Girish Gowdra996d81e2021-04-21 16:16:27 -0700315func createPptpResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse {
316 // Valid values for oper_state are 0 (enabled) and 1 (disabled)
317 // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks)
318 onuAdminState := 1
319 if !onuDown {
320 onuAdminState = 0
321 }
322 onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state
Matteo Scandolof9d43412021-01-12 11:11:34 -0800323 managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{
324 EntityID: entityID,
325 Attributes: me.AttributeValueMap{
326 "ManagedEntityId": entityID,
327 "ExpectedType": 0,
328 "SensedType": 0,
329 "AutoDetectionConfiguration": 0,
330 "EthernetLoopbackConfiguration": 0,
Girish Gowdra996d81e2021-04-21 16:16:27 -0700331 "AdministrativeState": onuAdminState,
332 "OperationalState": onuOperState,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800333 "ConfigurationInd": 0,
334 "MaxFrameSize": 0,
335 "DteOrDceInd": 0,
336 "PauseTime": 0,
337 "BridgedOrIpInd": 0,
338 "Arc": 0,
339 "ArcInterval": 0,
340 "PppoeFilter": 0,
341 "PowerControl": 0,
342 },
343 })
344
345 if meErr.GetError() != nil {
346 omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error())
347 return nil
348 }
349
350 return &omci.GetResponse{
351 MeBasePacket: omci.MeBasePacket{
Girish Gowdrac3fd50c2021-03-12 16:14:44 -0800352 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
353 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800354 },
355 Attributes: managedEntity.GetAttributeValueMap(),
356 AttributeMask: attributeMask,
357 Result: me.Success,
358 }
359}
360
Girish Gowdraa539f522021-02-15 23:00:45 -0800361func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800362 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{
Matteo Scandolof9d43412021-01-12 11:11:34 -0800363 EntityID: entityID,
364 Attributes: me.AttributeValueMap{
Girish Gowdraa539f522021-02-15 23:00:45 -0800365 "ManagedEntityId": entityID,
366 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
367 "ThresholdData12Id": 0,
368 "DropEvents": rand.Intn(100),
369 "Octets": rand.Intn(100),
370 "Packets": rand.Intn(100),
371 "BroadcastPackets": rand.Intn(100),
372 "MulticastPackets": rand.Intn(100),
373 "CrcErroredPackets": rand.Intn(100),
374 "UndersizePackets": rand.Intn(100),
375 "OversizePackets": rand.Intn(100),
376 "Packets64Octets": rand.Intn(100),
377 "Packets65To127Octets": rand.Intn(100),
378 "Packets128To255Octets": rand.Intn(100),
379 "Packets256To511Octets": rand.Intn(100),
380 "Packets512To1023Octets": rand.Intn(100),
381 "Packets1024To1518Octets": rand.Intn(100),
Matteo Scandolof9d43412021-01-12 11:11:34 -0800382 },
383 })
384
385 if meErr.GetError() != nil {
Girish Gowdraa539f522021-02-15 23:00:45 -0800386 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error())
Matteo Scandolof9d43412021-01-12 11:11:34 -0800387 return nil
388 }
389
390 return &omci.GetResponse{
391 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800392 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID,
393 EntityInstance: entityID,
394 },
395 Attributes: managedEntity.GetAttributeValueMap(),
396 AttributeMask: attributeMask,
397 Result: me.Success,
398 }
399}
400
401func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800402 managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{
403 EntityID: entityID,
404 Attributes: me.AttributeValueMap{
405 "ManagedEntityId": entityID,
406 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
407 "ThresholdData12Id": 0,
408 "DropEvents": rand.Intn(100),
409 "Octets": rand.Intn(100),
410 "Packets": rand.Intn(100),
411 "BroadcastPackets": rand.Intn(100),
412 "MulticastPackets": rand.Intn(100),
413 "CrcErroredPackets": rand.Intn(100),
414 "UndersizePackets": rand.Intn(100),
415 "OversizePackets": rand.Intn(100),
416 "Packets64Octets": rand.Intn(100),
417 "Packets65To127Octets": rand.Intn(100),
418 "Packets128To255Octets": rand.Intn(100),
419 "Packets256To511Octets": rand.Intn(100),
420 "Packets512To1023Octets": rand.Intn(100),
421 "Packets1024To1518Octets": rand.Intn(100),
422 },
423 })
424
425 if meErr.GetError() != nil {
426 omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error())
427 return nil
428 }
429
Girish Gowdraa539f522021-02-15 23:00:45 -0800430 return &omci.GetResponse{
431 MeBasePacket: omci.MeBasePacket{
432 EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID,
433 EntityInstance: entityID,
434 },
435 Attributes: managedEntity.GetAttributeValueMap(),
436 AttributeMask: attributeMask,
437 Result: me.Success,
438 }
439}
440
441func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
Girish Gowdraa539f522021-02-15 23:00:45 -0800442 managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{
443 EntityID: entityID,
444 Attributes: me.AttributeValueMap{
445 "ManagedEntityId": entityID,
446 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
447 "ThresholdData12Id": 0,
448 "FcsErrors": rand.Intn(100),
449 "ExcessiveCollisionCounter": rand.Intn(100),
450 "LateCollisionCounter": rand.Intn(100),
451 "FramesTooLong": rand.Intn(100),
452 "BufferOverflowsOnReceive": rand.Intn(100),
453 "BufferOverflowsOnTransmit": rand.Intn(100),
454 "SingleCollisionFrameCounter": rand.Intn(100),
455 "MultipleCollisionsFrameCounter": rand.Intn(100),
456 "SqeCounter": rand.Intn(100),
457 "DeferredTransmissionCounter": rand.Intn(100),
458 "InternalMacTransmitErrorCounter": rand.Intn(100),
459 "CarrierSenseErrorCounter": rand.Intn(100),
460 "AlignmentErrorCounter": rand.Intn(100),
461 "InternalMacReceiveErrorCounter": rand.Intn(100),
462 },
463 })
464
465 if meErr.GetError() != nil {
466 omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error())
467 return nil
468 }
469
Girish Gowdraa539f522021-02-15 23:00:45 -0800470 return &omci.GetResponse{
471 MeBasePacket: omci.MeBasePacket{
472 EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID,
473 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800474 },
475 Attributes: managedEntity.GetAttributeValueMap(),
476 AttributeMask: attributeMask,
477 Result: me.Success,
478 }
479}
480
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800481func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
482 managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{
483 EntityID: entityID,
484 Attributes: me.AttributeValueMap{
485 "ManagedEntityId": entityID,
486 "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
487 "ThresholdData12Id": 0,
488 "CorrectedBytes": rand.Intn(100),
489 "CorrectedCodeWords": rand.Intn(100),
490 "UncorrectableCodeWords": rand.Intn(100),
491 "TotalCodeWords": rand.Intn(100),
492 "FecSeconds": rand.Intn(100),
493 },
494 })
495
496 if meErr.GetError() != nil {
497 omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error())
498 return nil
499 }
500
501 // FEC History counter fits within single gem payload.
502 // No need of the logical we use in other Ethernet History counters or Gem Port History counters
503
504 return &omci.GetResponse{
505 MeBasePacket: omci.MeBasePacket{
506 EntityClass: me.FecPerformanceMonitoringHistoryDataClassID,
507 EntityInstance: entityID,
508 },
509 Attributes: managedEntity.GetAttributeValueMap(),
510 AttributeMask: attributeMask,
511 Result: me.Success,
512 }
513}
514
515func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse {
516 managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(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 "TransmittedGemFrames": rand.Intn(100),
523 "ReceivedGemFrames": rand.Intn(100),
524 "ReceivedPayloadBytes": rand.Intn(100),
525 "TransmittedPayloadBytes": rand.Intn(100),
526 "EncryptionKeyErrors": rand.Intn(100),
527 },
528 })
529
530 if meErr.GetError() != nil {
531 omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error())
532 return nil
533 }
534
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800535 return &omci.GetResponse{
536 MeBasePacket: omci.MeBasePacket{
537 EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID,
538 EntityInstance: entityID,
539 },
540 Attributes: managedEntity.GetAttributeValueMap(),
541 AttributeMask: attributeMask,
542 Result: me.Success,
543 }
544}
545
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800546func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800547 managedEntity, meErr := me.NewOnuData(me.ParamData{
548 EntityID: entityID,
549 Attributes: me.AttributeValueMap{
550 "ManagedEntityId": entityID,
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800551 "MibDataSync": mds,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800552 },
553 })
554
555 if meErr.GetError() != nil {
556 omciLogger.Errorf("NewOnuData %v", meErr.Error())
557 return nil
558 }
559
560 return &omci.GetResponse{
561 MeBasePacket: omci.MeBasePacket{
Girish Gowdraa539f522021-02-15 23:00:45 -0800562 EntityClass: me.OnuDataClassID,
563 EntityInstance: entityID,
564 },
565 Attributes: managedEntity.GetAttributeValueMap(),
566 AttributeMask: attributeMask,
567 Result: me.Success,
568 }
569}
570
571func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse {
572 managedEntity, meErr := me.NewAniG(me.ParamData{
573 EntityID: entityID,
574 Attributes: me.AttributeValueMap{
575 "ManagedEntityId": entityID,
576 "SrIndication": 0,
577 "TotalTcontNumber": 0,
578 "GemBlockLength": 0,
579 "PiggybackDbaReporting": 0,
580 "Deprecated": 0,
581 "SignalFailThreshold": 0,
582 "SignalDegradeThreshold": 0,
583 "Arc": 0,
584 "ArcInterval": 0,
585 "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
586 "LowerOpticalThreshold": 0,
587 "UpperOpticalThreshold": 0,
588 "OnuResponseTime": 0,
589 "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0
590 "LowerTransmitPowerThreshold": 0,
591 "UpperTransmitPowerThreshold": 0,
592 },
593 })
594
595 if meErr.GetError() != nil {
596 omciLogger.Errorf("NewAniG %v", meErr.Error())
597 return nil
598 }
599
600 return &omci.GetResponse{
601 MeBasePacket: omci.MeBasePacket{
602 EntityClass: me.AniGClassID,
603 EntityInstance: entityID,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800604 },
605 Attributes: managedEntity.GetAttributeValueMap(),
606 AttributeMask: attributeMask,
607 Result: me.Success,
608 }
609}
610
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700611func ToOctets(str string, size int) []byte {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800612 asciiBytes := []byte(str)
613
614 if len(asciiBytes) < size {
615 missing := size - len(asciiBytes)
616 for i := 0; i < missing; i++ {
617 asciiBytes = append(asciiBytes, []byte{0x00}[0])
618 }
619 }
620 return asciiBytes
621}