Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package omci |
| 18 | |
| 19 | import ( |
| 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 Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 26 | "github.com/opencord/voltha-protos/v4/go/openolt" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 27 | log "github.com/sirupsen/logrus" |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 28 | "math/rand" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 29 | "strconv" |
| 30 | ) |
| 31 | |
| 32 | func 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 | |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 48 | func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8, activeImageEntityId uint16, committedImageEntityId uint16, onuDown bool) ([]byte, error) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 49 | |
| 50 | msgObj, err := ParseGetRequest(omciPkt) |
| 51 | |
| 52 | if err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | |
| 56 | omciLogger.WithFields(log.Fields{ |
| 57 | "EntityClass": msgObj.EntityClass, |
| 58 | "EntityInstance": msgObj.EntityInstance, |
| 59 | "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask), |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 60 | }).Trace("received-omci-get-request") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 61 | |
| 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 Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 67 | response = createOnugResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuSn) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 68 | case me.SoftwareImageClassID: |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 69 | response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance, activeImageEntityId, committedImageEntityId) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 70 | case me.IpHostConfigDataClassID: |
| 71 | response = createIpHostResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 72 | case me.UniGClassID: |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 73 | response = createUnigResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 74 | case me.PhysicalPathTerminationPointEthernetUniClassID: |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 75 | response = createPptpResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 76 | case me.AniGClassID: |
| 77 | response = createAnigResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 78 | case me.OnuDataClassID: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 79 | response = createOnuDataResponse(msgObj.AttributeMask, msgObj.EntityInstance, mds) |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 80 | case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID: |
| 81 | response = createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 82 | case me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID: |
| 83 | response = createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 84 | case me.EthernetPerformanceMonitoringHistoryDataClassID: |
| 85 | response = createEthernetPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
Girish Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 86 | case me.FecPerformanceMonitoringHistoryDataClassID: |
| 87 | response = createFecPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 88 | case me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID: |
| 89 | response = createGemPortNetworkCtpPerformanceMonitoringHistoryData(msgObj.AttributeMask, msgObj.EntityInstance) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 90 | default: |
| 91 | omciLogger.WithFields(log.Fields{ |
| 92 | "EntityClass": msgObj.EntityClass, |
| 93 | "EntityInstance": msgObj.EntityInstance, |
| 94 | "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask), |
| 95 | }).Warnf("do-not-know-how-to-handle-get-request-for-me-class") |
| 96 | return nil, nil |
| 97 | } |
| 98 | |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 99 | pkt, err := Serialize(omci.GetResponseType, response, omciMsg.TransactionID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 100 | if err != nil { |
| 101 | omciLogger.WithFields(log.Fields{ |
| 102 | "Err": err, |
| 103 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
Matteo Scandolo | 78d5ee1 | 2021-04-14 11:11:32 -0700 | [diff] [blame] | 104 | }).Error("cannot-Serialize-GetResponse") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 105 | return nil, err |
| 106 | } |
| 107 | |
| 108 | log.WithFields(log.Fields{ |
| 109 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 110 | "pkt": hex.EncodeToString(pkt), |
| 111 | }).Trace("omci-get-response") |
| 112 | |
| 113 | return pkt, nil |
| 114 | } |
| 115 | |
| 116 | func createOnu2gResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 117 | |
| 118 | managedEntity, meErr := me.NewOnu2G(me.ParamData{ |
| 119 | EntityID: entityID, |
| 120 | Attributes: me.AttributeValueMap{ |
| 121 | "ManagedEntityId": entityID, |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 122 | "EquipmentId": toOctets("12345123451234512345", 20), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 123 | "OpticalNetworkUnitManagementAndControlChannelOmccVersion": 180, |
| 124 | "VendorProductCode": 0, |
| 125 | "SecurityCapability": 1, |
| 126 | "SecurityMode": 1, |
| 127 | "TotalPriorityQueueNumber": 1, |
| 128 | "TotalTrafficSchedulerNumber": 1, |
| 129 | "Deprecated": 1, |
| 130 | "TotalGemPortIdNumber": 32, |
| 131 | "Sysuptime": 319389947, // NOTE need to be smarter? |
| 132 | "ConnectivityCapability": 127, |
| 133 | "CurrentConnectivityMode": 5, |
| 134 | "QualityOfServiceQosConfigurationFlexibility": 48, |
| 135 | "PriorityQueueScaleFactor": 1, |
| 136 | }, |
| 137 | }) |
| 138 | |
| 139 | if meErr.GetError() != nil { |
| 140 | omciLogger.Errorf("NewOnu2G %v", meErr.Error()) |
| 141 | return nil |
| 142 | } |
| 143 | |
| 144 | return &omci.GetResponse{ |
| 145 | MeBasePacket: omci.MeBasePacket{ |
| 146 | EntityClass: me.Onu2GClassID, |
| 147 | }, |
| 148 | Attributes: managedEntity.GetAttributeValueMap(), |
| 149 | AttributeMask: attributeMask, |
| 150 | Result: me.Success, |
| 151 | } |
| 152 | } |
| 153 | |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 154 | func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse { |
| 155 | |
| 156 | managedEntity, meErr := me.NewOnuG(me.ParamData{ |
| 157 | EntityID: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 158 | Attributes: me.AttributeValueMap{ |
| 159 | "ManagedEntityId": entityID, |
| 160 | "VendorId": toOctets("BBSM", 4), |
| 161 | "Version": toOctets("v0.0.1", 14), |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 162 | "SerialNumber": append(onuSn.VendorId, onuSn.VendorSpecific...), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 163 | "TrafficManagementOption": 0, |
| 164 | "Deprecated": 0, |
| 165 | "BatteryBackup": 0, |
| 166 | "AdministrativeState": 0, |
| 167 | "OperationalState": 0, |
| 168 | "OnuSurvivalTime": 10, |
| 169 | "LogicalOnuId": toOctets("BBSM", 24), |
| 170 | "LogicalPassword": toOctets("BBSM", 12), |
| 171 | "CredentialsStatus": 0, |
| 172 | "ExtendedTcLayerOptions": 0, |
| 173 | }, |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 174 | }) |
| 175 | |
| 176 | if meErr.GetError() != nil { |
| 177 | omciLogger.Errorf("NewOnu2G %v", meErr.Error()) |
| 178 | return nil |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 179 | } |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 180 | |
| 181 | return &omci.GetResponse{ |
| 182 | MeBasePacket: omci.MeBasePacket{ |
| 183 | EntityClass: me.OnuGClassID, |
| 184 | }, |
| 185 | Attributes: managedEntity.GetAttributeValueMap(), |
| 186 | AttributeMask: attributeMask, |
| 187 | Result: me.Success, |
| 188 | } |
| 189 | |
| 190 | //return &omci.GetResponse{ |
| 191 | // MeBasePacket: omci.MeBasePacket{ |
| 192 | // EntityClass: me.OnuGClassID, |
| 193 | // EntityInstance: entityID, |
| 194 | // }, |
| 195 | // Attributes: me.AttributeValueMap{ |
| 196 | // |
| 197 | // }, |
| 198 | // Result: me.Success, |
| 199 | // AttributeMask: attributeMask, |
| 200 | //} |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 203 | func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16, activeImageEntityId uint16, committedImageEntityId uint16) *omci.GetResponse { |
| 204 | |
| 205 | omciLogger.WithFields(log.Fields{ |
| 206 | "EntityInstance": entityInstance, |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 207 | }).Trace("received-get-software-image-request") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 208 | |
| 209 | // Only one image can be active and committed |
| 210 | committed := 0 |
| 211 | active := 0 |
| 212 | if entityInstance == activeImageEntityId { |
| 213 | active = 1 |
| 214 | } |
| 215 | if entityInstance == committedImageEntityId { |
| 216 | committed = 1 |
| 217 | } |
| 218 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 219 | // NOTE that we need send the response for the correct ME Instance or the adapter won't process it |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 220 | res := &omci.GetResponse{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 221 | MeBasePacket: omci.MeBasePacket{ |
| 222 | EntityClass: me.SoftwareImageClassID, |
| 223 | EntityInstance: entityInstance, |
| 224 | }, |
| 225 | Attributes: me.AttributeValueMap{ |
| 226 | "ManagedEntityId": 0, |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 227 | "Version": toOctets("00000000000001", 14), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 228 | "IsCommitted": committed, |
| 229 | "IsActive": active, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 230 | "IsValid": 1, |
| 231 | "ProductCode": toOctets("product-code", 25), |
| 232 | "ImageHash": toOctets("broadband-sim", 16), |
| 233 | }, |
| 234 | Result: me.Success, |
| 235 | AttributeMask: attributeMask, |
| 236 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 237 | |
| 238 | omciLogger.WithFields(log.Fields{ |
| 239 | "omciMessage": res, |
| 240 | "entityId": entityInstance, |
| 241 | "active": active, |
| 242 | "committed": committed, |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 243 | }).Trace("Reporting SoftwareImage") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 244 | |
| 245 | return res |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | func createIpHostResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse { |
| 249 | return &omci.GetResponse{ |
| 250 | MeBasePacket: omci.MeBasePacket{ |
| 251 | EntityClass: me.IpHostConfigDataClassID, |
| 252 | EntityInstance: entityInstance, |
| 253 | }, |
| 254 | Attributes: me.AttributeValueMap{ |
| 255 | "ManagedEntityId": 0, |
| 256 | "MacAddress": toOctets("aabbcc", 6), |
| 257 | }, |
| 258 | Result: me.Success, |
| 259 | AttributeMask: attributeMask, |
| 260 | } |
| 261 | } |
| 262 | |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 263 | func createUnigResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse { |
| 264 | // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks) |
| 265 | omciAdminState := 1 |
| 266 | if !onuDown { |
| 267 | omciAdminState = 0 |
| 268 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 269 | managedEntity, meErr := me.NewUniG(me.ParamData{ |
| 270 | EntityID: entityID, |
| 271 | Attributes: me.AttributeValueMap{ |
| 272 | "ManagedEntityId": entityID, |
| 273 | "Deprecated": 0, |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 274 | "AdministrativeState": omciAdminState, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 275 | "ManagementCapability": 0, |
| 276 | "NonOmciManagementIdentifier": 1, |
| 277 | "RelayAgentOptions": 1, |
| 278 | }, |
| 279 | }) |
| 280 | |
| 281 | if meErr.GetError() != nil { |
| 282 | omciLogger.Errorf("NewUniG %v", meErr.Error()) |
| 283 | return nil |
| 284 | } |
| 285 | |
| 286 | return &omci.GetResponse{ |
| 287 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | c3fd50c | 2021-03-12 16:14:44 -0800 | [diff] [blame] | 288 | EntityClass: me.UniGClassID, |
| 289 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 290 | }, |
| 291 | Attributes: managedEntity.GetAttributeValueMap(), |
| 292 | AttributeMask: attributeMask, |
| 293 | Result: me.Success, |
| 294 | } |
| 295 | } |
| 296 | |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 297 | func createPptpResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse { |
| 298 | // Valid values for oper_state are 0 (enabled) and 1 (disabled) |
| 299 | // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks) |
| 300 | onuAdminState := 1 |
| 301 | if !onuDown { |
| 302 | onuAdminState = 0 |
| 303 | } |
| 304 | onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 305 | managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{ |
| 306 | EntityID: entityID, |
| 307 | Attributes: me.AttributeValueMap{ |
| 308 | "ManagedEntityId": entityID, |
| 309 | "ExpectedType": 0, |
| 310 | "SensedType": 0, |
| 311 | "AutoDetectionConfiguration": 0, |
| 312 | "EthernetLoopbackConfiguration": 0, |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 313 | "AdministrativeState": onuAdminState, |
| 314 | "OperationalState": onuOperState, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 315 | "ConfigurationInd": 0, |
| 316 | "MaxFrameSize": 0, |
| 317 | "DteOrDceInd": 0, |
| 318 | "PauseTime": 0, |
| 319 | "BridgedOrIpInd": 0, |
| 320 | "Arc": 0, |
| 321 | "ArcInterval": 0, |
| 322 | "PppoeFilter": 0, |
| 323 | "PowerControl": 0, |
| 324 | }, |
| 325 | }) |
| 326 | |
| 327 | if meErr.GetError() != nil { |
| 328 | omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error()) |
| 329 | return nil |
| 330 | } |
| 331 | |
| 332 | return &omci.GetResponse{ |
| 333 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | c3fd50c | 2021-03-12 16:14:44 -0800 | [diff] [blame] | 334 | EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 335 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 336 | }, |
| 337 | Attributes: managedEntity.GetAttributeValueMap(), |
| 338 | AttributeMask: attributeMask, |
| 339 | Result: me.Success, |
| 340 | } |
| 341 | } |
| 342 | |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 343 | func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 344 | managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 345 | EntityID: entityID, |
| 346 | Attributes: me.AttributeValueMap{ |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 347 | "ManagedEntityId": entityID, |
| 348 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 349 | "ThresholdData12Id": 0, |
| 350 | "DropEvents": rand.Intn(100), |
| 351 | "Octets": rand.Intn(100), |
| 352 | "Packets": rand.Intn(100), |
| 353 | "BroadcastPackets": rand.Intn(100), |
| 354 | "MulticastPackets": rand.Intn(100), |
| 355 | "CrcErroredPackets": rand.Intn(100), |
| 356 | "UndersizePackets": rand.Intn(100), |
| 357 | "OversizePackets": rand.Intn(100), |
| 358 | "Packets64Octets": rand.Intn(100), |
| 359 | "Packets65To127Octets": rand.Intn(100), |
| 360 | "Packets128To255Octets": rand.Intn(100), |
| 361 | "Packets256To511Octets": rand.Intn(100), |
| 362 | "Packets512To1023Octets": rand.Intn(100), |
| 363 | "Packets1024To1518Octets": rand.Intn(100), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 364 | }, |
| 365 | }) |
| 366 | |
| 367 | if meErr.GetError() != nil { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 368 | omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error()) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 369 | return nil |
| 370 | } |
| 371 | |
| 372 | return &omci.GetResponse{ |
| 373 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 374 | EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID, |
| 375 | EntityInstance: entityID, |
| 376 | }, |
| 377 | Attributes: managedEntity.GetAttributeValueMap(), |
| 378 | AttributeMask: attributeMask, |
| 379 | Result: me.Success, |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 384 | managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{ |
| 385 | EntityID: entityID, |
| 386 | Attributes: me.AttributeValueMap{ |
| 387 | "ManagedEntityId": entityID, |
| 388 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 389 | "ThresholdData12Id": 0, |
| 390 | "DropEvents": rand.Intn(100), |
| 391 | "Octets": rand.Intn(100), |
| 392 | "Packets": rand.Intn(100), |
| 393 | "BroadcastPackets": rand.Intn(100), |
| 394 | "MulticastPackets": rand.Intn(100), |
| 395 | "CrcErroredPackets": rand.Intn(100), |
| 396 | "UndersizePackets": rand.Intn(100), |
| 397 | "OversizePackets": rand.Intn(100), |
| 398 | "Packets64Octets": rand.Intn(100), |
| 399 | "Packets65To127Octets": rand.Intn(100), |
| 400 | "Packets128To255Octets": rand.Intn(100), |
| 401 | "Packets256To511Octets": rand.Intn(100), |
| 402 | "Packets512To1023Octets": rand.Intn(100), |
| 403 | "Packets1024To1518Octets": rand.Intn(100), |
| 404 | }, |
| 405 | }) |
| 406 | |
| 407 | if meErr.GetError() != nil { |
| 408 | omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error()) |
| 409 | return nil |
| 410 | } |
| 411 | |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 412 | return &omci.GetResponse{ |
| 413 | MeBasePacket: omci.MeBasePacket{ |
| 414 | EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID, |
| 415 | EntityInstance: entityID, |
| 416 | }, |
| 417 | Attributes: managedEntity.GetAttributeValueMap(), |
| 418 | AttributeMask: attributeMask, |
| 419 | Result: me.Success, |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 424 | managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{ |
| 425 | EntityID: entityID, |
| 426 | Attributes: me.AttributeValueMap{ |
| 427 | "ManagedEntityId": entityID, |
| 428 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 429 | "ThresholdData12Id": 0, |
| 430 | "FcsErrors": rand.Intn(100), |
| 431 | "ExcessiveCollisionCounter": rand.Intn(100), |
| 432 | "LateCollisionCounter": rand.Intn(100), |
| 433 | "FramesTooLong": rand.Intn(100), |
| 434 | "BufferOverflowsOnReceive": rand.Intn(100), |
| 435 | "BufferOverflowsOnTransmit": rand.Intn(100), |
| 436 | "SingleCollisionFrameCounter": rand.Intn(100), |
| 437 | "MultipleCollisionsFrameCounter": rand.Intn(100), |
| 438 | "SqeCounter": rand.Intn(100), |
| 439 | "DeferredTransmissionCounter": rand.Intn(100), |
| 440 | "InternalMacTransmitErrorCounter": rand.Intn(100), |
| 441 | "CarrierSenseErrorCounter": rand.Intn(100), |
| 442 | "AlignmentErrorCounter": rand.Intn(100), |
| 443 | "InternalMacReceiveErrorCounter": rand.Intn(100), |
| 444 | }, |
| 445 | }) |
| 446 | |
| 447 | if meErr.GetError() != nil { |
| 448 | omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error()) |
| 449 | return nil |
| 450 | } |
| 451 | |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 452 | return &omci.GetResponse{ |
| 453 | MeBasePacket: omci.MeBasePacket{ |
| 454 | EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID, |
| 455 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 456 | }, |
| 457 | Attributes: managedEntity.GetAttributeValueMap(), |
| 458 | AttributeMask: attributeMask, |
| 459 | Result: me.Success, |
| 460 | } |
| 461 | } |
| 462 | |
Girish Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 463 | func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 464 | managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{ |
| 465 | EntityID: entityID, |
| 466 | Attributes: me.AttributeValueMap{ |
| 467 | "ManagedEntityId": entityID, |
| 468 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 469 | "ThresholdData12Id": 0, |
| 470 | "CorrectedBytes": rand.Intn(100), |
| 471 | "CorrectedCodeWords": rand.Intn(100), |
| 472 | "UncorrectableCodeWords": rand.Intn(100), |
| 473 | "TotalCodeWords": rand.Intn(100), |
| 474 | "FecSeconds": rand.Intn(100), |
| 475 | }, |
| 476 | }) |
| 477 | |
| 478 | if meErr.GetError() != nil { |
| 479 | omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error()) |
| 480 | return nil |
| 481 | } |
| 482 | |
| 483 | // FEC History counter fits within single gem payload. |
| 484 | // No need of the logical we use in other Ethernet History counters or Gem Port History counters |
| 485 | |
| 486 | return &omci.GetResponse{ |
| 487 | MeBasePacket: omci.MeBasePacket{ |
| 488 | EntityClass: me.FecPerformanceMonitoringHistoryDataClassID, |
| 489 | EntityInstance: entityID, |
| 490 | }, |
| 491 | Attributes: managedEntity.GetAttributeValueMap(), |
| 492 | AttributeMask: attributeMask, |
| 493 | Result: me.Success, |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 498 | managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{ |
| 499 | EntityID: entityID, |
| 500 | Attributes: me.AttributeValueMap{ |
| 501 | "ManagedEntityId": entityID, |
| 502 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 503 | "ThresholdData12Id": 0, |
| 504 | "TransmittedGemFrames": rand.Intn(100), |
| 505 | "ReceivedGemFrames": rand.Intn(100), |
| 506 | "ReceivedPayloadBytes": rand.Intn(100), |
| 507 | "TransmittedPayloadBytes": rand.Intn(100), |
| 508 | "EncryptionKeyErrors": rand.Intn(100), |
| 509 | }, |
| 510 | }) |
| 511 | |
| 512 | if meErr.GetError() != nil { |
| 513 | omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error()) |
| 514 | return nil |
| 515 | } |
| 516 | |
Girish Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 517 | return &omci.GetResponse{ |
| 518 | MeBasePacket: omci.MeBasePacket{ |
| 519 | EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID, |
| 520 | EntityInstance: entityID, |
| 521 | }, |
| 522 | Attributes: managedEntity.GetAttributeValueMap(), |
| 523 | AttributeMask: attributeMask, |
| 524 | Result: me.Success, |
| 525 | } |
| 526 | } |
| 527 | |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 528 | func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 529 | managedEntity, meErr := me.NewOnuData(me.ParamData{ |
| 530 | EntityID: entityID, |
| 531 | Attributes: me.AttributeValueMap{ |
| 532 | "ManagedEntityId": entityID, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 533 | "MibDataSync": mds, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 534 | }, |
| 535 | }) |
| 536 | |
| 537 | if meErr.GetError() != nil { |
| 538 | omciLogger.Errorf("NewOnuData %v", meErr.Error()) |
| 539 | return nil |
| 540 | } |
| 541 | |
| 542 | return &omci.GetResponse{ |
| 543 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 544 | EntityClass: me.OnuDataClassID, |
| 545 | EntityInstance: entityID, |
| 546 | }, |
| 547 | Attributes: managedEntity.GetAttributeValueMap(), |
| 548 | AttributeMask: attributeMask, |
| 549 | Result: me.Success, |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 554 | managedEntity, meErr := me.NewAniG(me.ParamData{ |
| 555 | EntityID: entityID, |
| 556 | Attributes: me.AttributeValueMap{ |
| 557 | "ManagedEntityId": entityID, |
| 558 | "SrIndication": 0, |
| 559 | "TotalTcontNumber": 0, |
| 560 | "GemBlockLength": 0, |
| 561 | "PiggybackDbaReporting": 0, |
| 562 | "Deprecated": 0, |
| 563 | "SignalFailThreshold": 0, |
| 564 | "SignalDegradeThreshold": 0, |
| 565 | "Arc": 0, |
| 566 | "ArcInterval": 0, |
| 567 | "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0 |
| 568 | "LowerOpticalThreshold": 0, |
| 569 | "UpperOpticalThreshold": 0, |
| 570 | "OnuResponseTime": 0, |
| 571 | "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0 |
| 572 | "LowerTransmitPowerThreshold": 0, |
| 573 | "UpperTransmitPowerThreshold": 0, |
| 574 | }, |
| 575 | }) |
| 576 | |
| 577 | if meErr.GetError() != nil { |
| 578 | omciLogger.Errorf("NewAniG %v", meErr.Error()) |
| 579 | return nil |
| 580 | } |
| 581 | |
| 582 | return &omci.GetResponse{ |
| 583 | MeBasePacket: omci.MeBasePacket{ |
| 584 | EntityClass: me.AniGClassID, |
| 585 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 586 | }, |
| 587 | Attributes: managedEntity.GetAttributeValueMap(), |
| 588 | AttributeMask: attributeMask, |
| 589 | Result: me.Success, |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | func toOctets(str string, size int) []byte { |
| 594 | asciiBytes := []byte(str) |
| 595 | |
| 596 | if len(asciiBytes) < size { |
| 597 | missing := size - len(asciiBytes) |
| 598 | for i := 0; i < missing; i++ { |
| 599 | asciiBytes = append(asciiBytes, []byte{0x00}[0]) |
| 600 | } |
| 601 | } |
| 602 | return asciiBytes |
| 603 | } |