blob: 6d83495c1c8be30301dc97ece30d3e0f7aed65cb [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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100129 me.ManagedEntityID: entityID,
130 me.Onu2G_EquipmentId: ToOctets("12345123451234512345", 20),
131 me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion: 180,
132 me.Onu2G_VendorProductCode: 0,
133 me.Onu2G_SecurityCapability: 1,
134 me.Onu2G_SecurityMode: 1,
135 me.Onu2G_TotalPriorityQueueNumber: 1,
136 me.Onu2G_TotalTrafficSchedulerNumber: 1,
137 me.Onu2G_Deprecated: 1,
138 me.Onu2G_TotalGemPortIdNumber: 32,
139 me.Onu2G_Sysuptime: 319389947, // NOTE need to be smarter?
140 me.Onu2G_ConnectivityCapability: 127,
141 me.Onu2G_CurrentConnectivityMode: 5,
142 me.Onu2G_QualityOfServiceQosConfigurationFlexibility: 48,
143 me.Onu2G_PriorityQueueScaleFactor: 1,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800144 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100167 me.ManagedEntityID: entityID,
168 me.OnuG_VendorId: ToOctets("BBSM", 4),
169 me.OnuG_Version: ToOctets("v0.0.1", 14),
170 me.OnuG_SerialNumber: append(onuSn.VendorId, onuSn.VendorSpecific...),
171 me.OnuG_TrafficManagementOption: 0,
172 me.OnuG_Deprecated: 0,
173 me.OnuG_BatteryBackup: 0,
174 me.OnuG_AdministrativeState: 0,
175 me.OnuG_OperationalState: 0,
176 me.OnuG_OnuSurvivalTime: 10,
177 me.OnuG_LogicalOnuId: ToOctets("BBSM", 24),
178 me.OnuG_LogicalPassword: ToOctets("BBSM", 12),
179 me.OnuG_CredentialsStatus: 0,
180 me.OnuG_ExtendedTcLayerOptions: 0,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800181 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100249 me.ManagedEntityID: 0,
250 me.SoftwareImage_Version: ToOctets(version, 14),
251 me.SoftwareImage_IsCommitted: committed,
252 me.SoftwareImage_IsActive: active,
253 me.SoftwareImage_IsValid: 1,
254 me.SoftwareImage_ProductCode: ToOctets("BBSIM-ONU", 25),
255 me.SoftwareImage_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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100278 me.ManagedEntityID: 0,
279 me.IpHostConfigData_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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100293 me.ManagedEntityID: 0,
294 me.VoipConfigData_AvailableSignallingProtocols: 1,
295 me.VoipConfigData_SignallingProtocolUsed: 1,
296 me.VoipConfigData_AvailableVoipConfigurationMethods: 1,
297 me.VoipConfigData_VoipConfigurationMethodUsed: 1,
298 me.VoipConfigData_VoipConfigurationAddressPointer: 0xFFFF,
299 me.VoipConfigData_VoipConfigurationState: 0,
300 me.VoipConfigData_RetrieveProfile: 0,
301 me.VoipConfigData_ProfileVersion: 0,
Elia Battistonac63b112022-01-12 18:40:49 +0100302 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100317 me.ManagedEntityID: entityID,
318 me.UniG_Deprecated: 0,
319 me.UniG_AdministrativeState: omciAdminState,
320 me.UniG_ManagementCapability: 0,
321 me.UniG_NonOmciManagementIdentifier: 1,
322 me.UniG_RelayAgentOptions: 1,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800323 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100353 me.ManagedEntityID: entityID,
354 me.PhysicalPathTerminationPointEthernetUni_ExpectedType: 0,
355 me.PhysicalPathTerminationPointEthernetUni_SensedType: 0,
356 me.PhysicalPathTerminationPointEthernetUni_AutoDetectionConfiguration: 0,
357 me.PhysicalPathTerminationPointEthernetUni_EthernetLoopbackConfiguration: 0,
358 me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: onuAdminState,
359 me.PhysicalPathTerminationPointEthernetUni_OperationalState: onuOperState,
360 me.PhysicalPathTerminationPointEthernetUni_ConfigurationInd: 0,
361 me.PhysicalPathTerminationPointEthernetUni_MaxFrameSize: 0,
362 me.PhysicalPathTerminationPointEthernetUni_DteOrDceInd: 0,
363 me.PhysicalPathTerminationPointEthernetUni_PauseTime: 0,
364 me.PhysicalPathTerminationPointEthernetUni_BridgedOrIpInd: 0,
365 me.PhysicalPathTerminationPointEthernetUni_Arc: 0,
366 me.PhysicalPathTerminationPointEthernetUni_ArcInterval: 0,
367 me.PhysicalPathTerminationPointEthernetUni_PppoeFilter: 0,
368 me.PhysicalPathTerminationPointEthernetUni_PowerControl: 0,
Matteo Scandolof9d43412021-01-12 11:11:34 -0800369 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100399 me.ManagedEntityID: entityID,
400 me.PhysicalPathTerminationPointPotsUni_AdministrativeState: onuAdminState,
401 me.PhysicalPathTerminationPointPotsUni_Deprecated: 0,
402 me.PhysicalPathTerminationPointPotsUni_Arc: 0,
403 me.PhysicalPathTerminationPointPotsUni_ArcInterval: 0,
404 me.PhysicalPathTerminationPointPotsUni_Impedance: 0,
405 me.PhysicalPathTerminationPointPotsUni_TransmissionPath: 0,
406 me.PhysicalPathTerminationPointPotsUni_RxGain: 0,
407 me.PhysicalPathTerminationPointPotsUni_TxGain: 0,
408 me.PhysicalPathTerminationPointPotsUni_OperationalState: onuOperState,
409 me.PhysicalPathTerminationPointPotsUni_HookState: 0,
410 me.PhysicalPathTerminationPointPotsUni_PotsHoldoverTime: 0,
411 me.PhysicalPathTerminationPointPotsUni_NominalFeedVoltage: 0,
412 me.PhysicalPathTerminationPointPotsUni_LossOfSoftswitch: 0,
Elia Battistonac63b112022-01-12 18:40:49 +0100413 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100436 me.ManagedEntityID: entityID,
437 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_IntervalEndTime: 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
438 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_ThresholdData12Id: 0,
439 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_DropEvents: rand.Intn(100),
440 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Octets: rand.Intn(100),
441 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets: rand.Intn(100),
442 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_BroadcastPackets: rand.Intn(100),
443 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_MulticastPackets: rand.Intn(100),
444 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_CrcErroredPackets: rand.Intn(100),
445 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_UndersizePackets: rand.Intn(100),
446 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_OversizePackets: rand.Intn(100),
447 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets64Octets: rand.Intn(100),
448 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets65To127Octets: rand.Intn(100),
449 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets128To255Octets: rand.Intn(100),
450 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets256To511Octets: rand.Intn(100),
451 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets512To1023Octets: rand.Intn(100),
452 me.EthernetFramePerformanceMonitoringHistoryDataUpstream_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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100476 me.ManagedEntityID: entityID,
477 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_IntervalEndTime: 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
478 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_ThresholdData12Id: 0,
479 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_DropEvents: rand.Intn(100),
480 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_Octets: rand.Intn(100),
481 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_Packets: rand.Intn(100),
482 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_BroadcastPackets: rand.Intn(100),
483 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_MulticastPackets: rand.Intn(100),
484 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_CrcErroredPackets: rand.Intn(100),
485 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_UndersizePackets: rand.Intn(100),
486 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_OversizePackets: rand.Intn(100),
487 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_Packets64Octets: rand.Intn(100),
488 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_Packets65To127Octets: rand.Intn(100),
489 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_Packets128To255Octets: rand.Intn(100),
490 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_Packets256To511Octets: rand.Intn(100),
491 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_Packets512To1023Octets: rand.Intn(100),
492 me.EthernetFramePerformanceMonitoringHistoryDataDownstream_Packets1024To1518Octets: rand.Intn(100),
Girish Gowdraa539f522021-02-15 23:00:45 -0800493 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100516 me.ManagedEntityID: entityID,
517 me.EthernetPerformanceMonitoringHistoryData_IntervalEndTime: 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
518 me.EthernetPerformanceMonitoringHistoryData_ThresholdData12Id: 0,
519 me.EthernetPerformanceMonitoringHistoryData_FcsErrors: rand.Intn(100),
520 me.EthernetPerformanceMonitoringHistoryData_ExcessiveCollisionCounter: rand.Intn(100),
521 me.EthernetPerformanceMonitoringHistoryData_LateCollisionCounter: rand.Intn(100),
522 me.EthernetPerformanceMonitoringHistoryData_FramesTooLong: rand.Intn(100),
523 me.EthernetPerformanceMonitoringHistoryData_BufferOverflowsOnReceive: rand.Intn(100),
524 me.EthernetPerformanceMonitoringHistoryData_BufferOverflowsOnTransmit: rand.Intn(100),
525 me.EthernetPerformanceMonitoringHistoryData_SingleCollisionFrameCounter: rand.Intn(100),
526 me.EthernetPerformanceMonitoringHistoryData_MultipleCollisionsFrameCounter: rand.Intn(100),
527 me.EthernetPerformanceMonitoringHistoryData_SqeCounter: rand.Intn(100),
528 me.EthernetPerformanceMonitoringHistoryData_DeferredTransmissionCounter: rand.Intn(100),
529 me.EthernetPerformanceMonitoringHistoryData_InternalMacTransmitErrorCounter: rand.Intn(100),
530 me.EthernetPerformanceMonitoringHistoryData_CarrierSenseErrorCounter: rand.Intn(100),
531 me.EthernetPerformanceMonitoringHistoryData_AlignmentErrorCounter: rand.Intn(100),
532 me.EthernetPerformanceMonitoringHistoryData_InternalMacReceiveErrorCounter: rand.Intn(100),
Girish Gowdraa539f522021-02-15 23:00:45 -0800533 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100556 me.ManagedEntityID: entityID,
557 me.FecPerformanceMonitoringHistoryData_IntervalEndTime: 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
558 me.FecPerformanceMonitoringHistoryData_ThresholdData12Id: 0,
559 me.FecPerformanceMonitoringHistoryData_CorrectedBytes: rand.Intn(100),
560 me.FecPerformanceMonitoringHistoryData_CorrectedCodeWords: rand.Intn(100),
561 me.FecPerformanceMonitoringHistoryData_UncorrectableCodeWords: rand.Intn(100),
562 me.FecPerformanceMonitoringHistoryData_TotalCodeWords: rand.Intn(100),
563 me.FecPerformanceMonitoringHistoryData_FecSeconds: rand.Intn(100),
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800564 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100590 me.ManagedEntityID: entityID,
591 me.GemPortNetworkCtpPerformanceMonitoringHistoryData_IntervalEndTime: 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now.
592 me.GemPortNetworkCtpPerformanceMonitoringHistoryData_ThresholdData12Id: 0,
593 me.GemPortNetworkCtpPerformanceMonitoringHistoryData_TransmittedGemFrames: rand.Intn(100),
594 me.GemPortNetworkCtpPerformanceMonitoringHistoryData_ReceivedGemFrames: rand.Intn(100),
595 me.GemPortNetworkCtpPerformanceMonitoringHistoryData_ReceivedPayloadBytes: rand.Intn(100),
596 me.GemPortNetworkCtpPerformanceMonitoringHistoryData_TransmittedPayloadBytes: rand.Intn(100),
597 me.GemPortNetworkCtpPerformanceMonitoringHistoryData_EncryptionKeyErrors: rand.Intn(100),
Girish Gowdra6d9a1a42021-03-05 16:07:15 -0800598 },
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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100621 me.ManagedEntityID: entityID,
622 me.OnuData_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{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100646 me.ManagedEntityID: entityID,
647 me.AniG_SrIndication: 0,
648 me.AniG_TotalTcontNumber: 0,
649 me.AniG_GemBlockLength: 0,
650 me.AniG_PiggybackDbaReporting: 0,
651 me.AniG_Deprecated: 0,
652 me.AniG_SignalFailThreshold: 0,
653 me.AniG_SignalDegradeThreshold: 0,
654 me.AniG_Arc: 0,
655 me.AniG_ArcInterval: 0,
656 me.AniG_OpticalSignalLevel: rand.Intn(16000), // generate some random power level than defaulting to 0
657 me.AniG_LowerOpticalThreshold: 0,
658 me.AniG_UpperOpticalThreshold: 0,
659 me.AniG_OnuResponseTime: 0,
660 me.AniG_TransmitOpticalLevel: rand.Intn(16000), // generate some random power level than defaulting to 0
661 me.AniG_LowerTransmitPowerThreshold: 0,
662 me.AniG_UpperTransmitPowerThreshold: 0,
Girish Gowdraa539f522021-02-15 23:00:45 -0800663 },
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 }
Elia Battiston9bfe1102022-02-03 10:38:03 +0100688
689 //The names of these attributes are left as strings
690 //rather than constants of a particular ME because
691 //they can be used with both the MEs in the lines above
Himani Chawla908a1f52022-01-27 14:39:44 +0530692 attr := me.AttributeValueMap{
Elia Battiston9bfe1102022-02-03 10:38:03 +0100693 me.ManagedEntityID: entityID,
Himani Chawla908a1f52022-01-27 14:39:44 +0530694 "DropEvents": 100,
695 "Octets": 101,
696 "Frames": 102,
697 "BroadcastFrames": 103,
698 "MulticastFrames": 104,
699 "CrcErroredFrames": 105,
700 "UndersizeFrames": 106,
701 "OversizeFrames": 107,
702 "Frames64Octets": 108,
703 "Frames65To127Octets": 109,
704 "Frames128To255Octets": 110,
705 "Frames256To511Octets": 111,
706 "Frames512To1023Octets": 112,
707 "Frames1024To1518Octets": 113,
708 }
Himani Chawla6bd190a2021-07-09 15:31:01 +0530709 managedEntity, meErr := callback(me.ParamData{
Himani Chawla908a1f52022-01-27 14:39:44 +0530710 EntityID: entityID,
711 Attributes: attr,
Himani Chawla6bd190a2021-07-09 15:31:01 +0530712 })
713
714 if meErr.GetError() != nil {
715 omciLogger.Errorf("NewEthernetFrameExtendedPm %v", meErr.Error())
716 return nil
717 }
718
719 return &omci.GetResponse{
720 MeBasePacket: omci.MeBasePacket{
721 EntityClass: meClass,
722 EntityInstance: entityID,
723 },
724 Attributes: managedEntity.GetAttributeValueMap(),
725 AttributeMask: attributeMask,
726 Result: me.Success,
727 }
728}
729
Matteo Scandoloef4e8f82021-05-17 11:20:49 -0700730func ToOctets(str string, size int) []byte {
Matteo Scandolof9d43412021-01-12 11:11:34 -0800731 asciiBytes := []byte(str)
732
733 if len(asciiBytes) < size {
734 missing := size - len(asciiBytes)
735 for i := 0; i < missing; i++ {
736 asciiBytes = append(asciiBytes, []byte{0x00}[0])
737 }
738 }
739 return asciiBytes
740}