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 | |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 48 | func 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 Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 51 | |
| 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 Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 62 | }).Trace("received-omci-get-request") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 63 | |
| 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 Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 69 | response = createOnugResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuSn) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 70 | case me.SoftwareImageClassID: |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 71 | response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance, |
| 72 | activeImageEntityId, committedImageEntityId, standbyImageVersion, activeImageVersion, committedImageVersion) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 73 | case me.IpHostConfigDataClassID: |
| 74 | response = createIpHostResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 75 | case me.UniGClassID: |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 76 | response = createUnigResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 77 | case me.PhysicalPathTerminationPointEthernetUniClassID: |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 78 | response = createPptpResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 79 | case me.AniGClassID: |
| 80 | response = createAnigResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 81 | case me.OnuDataClassID: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 82 | response = createOnuDataResponse(msgObj.AttributeMask, msgObj.EntityInstance, mds) |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 83 | 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 Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 89 | case me.FecPerformanceMonitoringHistoryDataClassID: |
| 90 | response = createFecPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 91 | case me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID: |
| 92 | response = createGemPortNetworkCtpPerformanceMonitoringHistoryData(msgObj.AttributeMask, msgObj.EntityInstance) |
Himani Chawla | 6bd190a | 2021-07-09 15:31:01 +0530 | [diff] [blame] | 93 | case me.EthernetFrameExtendedPmClassID, |
| 94 | me.EthernetFrameExtendedPm64BitClassID: |
| 95 | response = createEthernetFrameExtendedPmGetResponse(msgObj.EntityClass, msgObj.AttributeMask, msgObj.EntityInstance) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 96 | 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 Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 105 | pkt, err := Serialize(omci.GetResponseType, response, omciMsg.TransactionID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 106 | if err != nil { |
| 107 | omciLogger.WithFields(log.Fields{ |
| 108 | "Err": err, |
| 109 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
Matteo Scandolo | 78d5ee1 | 2021-04-14 11:11:32 -0700 | [diff] [blame] | 110 | }).Error("cannot-Serialize-GetResponse") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 111 | 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 | |
| 122 | func 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 Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 128 | "EquipmentId": ToOctets("12345123451234512345", 20), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 129 | "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 Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 160 | func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse { |
| 161 | |
| 162 | managedEntity, meErr := me.NewOnuG(me.ParamData{ |
| 163 | EntityID: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 164 | Attributes: me.AttributeValueMap{ |
| 165 | "ManagedEntityId": entityID, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 166 | "VendorId": ToOctets("BBSM", 4), |
| 167 | "Version": ToOctets("v0.0.1", 14), |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 168 | "SerialNumber": append(onuSn.VendorId, onuSn.VendorSpecific...), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 169 | "TrafficManagementOption": 0, |
| 170 | "Deprecated": 0, |
| 171 | "BatteryBackup": 0, |
| 172 | "AdministrativeState": 0, |
| 173 | "OperationalState": 0, |
| 174 | "OnuSurvivalTime": 10, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 175 | "LogicalOnuId": ToOctets("BBSM", 24), |
| 176 | "LogicalPassword": ToOctets("BBSM", 12), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 177 | "CredentialsStatus": 0, |
| 178 | "ExtendedTcLayerOptions": 0, |
| 179 | }, |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 180 | }) |
| 181 | |
| 182 | if meErr.GetError() != nil { |
| 183 | omciLogger.Errorf("NewOnu2G %v", meErr.Error()) |
| 184 | return nil |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 185 | } |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 186 | |
| 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 Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 209 | func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16, activeImageEntityId uint16, |
| 210 | committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string, committedImageVersion string) *omci.GetResponse { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 211 | |
| 212 | omciLogger.WithFields(log.Fields{ |
| 213 | "EntityInstance": entityInstance, |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 214 | "AttributeMask": attributeMask, |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 215 | }).Trace("received-get-software-image-request") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 216 | |
| 217 | // Only one image can be active and committed |
| 218 | committed := 0 |
| 219 | active := 0 |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 220 | version := standbyImageVersion |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 221 | if entityInstance == activeImageEntityId { |
| 222 | active = 1 |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 223 | version = activeImageVersion |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 224 | } |
| 225 | if entityInstance == committedImageEntityId { |
| 226 | committed = 1 |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 227 | 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 Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 240 | // 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] | 241 | res := &omci.GetResponse{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 242 | MeBasePacket: omci.MeBasePacket{ |
| 243 | EntityClass: me.SoftwareImageClassID, |
| 244 | EntityInstance: entityInstance, |
| 245 | }, |
| 246 | Attributes: me.AttributeValueMap{ |
| 247 | "ManagedEntityId": 0, |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 248 | "Version": ToOctets(version, 14), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 249 | "IsCommitted": committed, |
| 250 | "IsActive": active, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 251 | "IsValid": 1, |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 252 | "ProductCode": ToOctets("BBSIM-ONU", 25), |
| 253 | "ImageHash": imageHash, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 254 | }, |
| 255 | Result: me.Success, |
| 256 | AttributeMask: attributeMask, |
| 257 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 258 | |
| 259 | omciLogger.WithFields(log.Fields{ |
| 260 | "omciMessage": res, |
| 261 | "entityId": entityInstance, |
| 262 | "active": active, |
| 263 | "committed": committed, |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 264 | }).Trace("Reporting SoftwareImage") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 265 | |
| 266 | return res |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | func 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 Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 277 | "MacAddress": ToOctets("aabbcc", 6), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 278 | }, |
| 279 | Result: me.Success, |
| 280 | AttributeMask: attributeMask, |
| 281 | } |
| 282 | } |
| 283 | |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 284 | func 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 Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 290 | managedEntity, meErr := me.NewUniG(me.ParamData{ |
| 291 | EntityID: entityID, |
| 292 | Attributes: me.AttributeValueMap{ |
| 293 | "ManagedEntityId": entityID, |
| 294 | "Deprecated": 0, |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 295 | "AdministrativeState": omciAdminState, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 296 | "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 Gowdra | c3fd50c | 2021-03-12 16:14:44 -0800 | [diff] [blame] | 309 | EntityClass: me.UniGClassID, |
| 310 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 311 | }, |
| 312 | Attributes: managedEntity.GetAttributeValueMap(), |
| 313 | AttributeMask: attributeMask, |
| 314 | Result: me.Success, |
| 315 | } |
| 316 | } |
| 317 | |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 318 | func 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 Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 326 | 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 Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 334 | "AdministrativeState": onuAdminState, |
| 335 | "OperationalState": onuOperState, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 336 | "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 Gowdra | c3fd50c | 2021-03-12 16:14:44 -0800 | [diff] [blame] | 355 | EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 356 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 357 | }, |
| 358 | Attributes: managedEntity.GetAttributeValueMap(), |
| 359 | AttributeMask: attributeMask, |
| 360 | Result: me.Success, |
| 361 | } |
| 362 | } |
| 363 | |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 364 | func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 365 | managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 366 | EntityID: entityID, |
| 367 | Attributes: me.AttributeValueMap{ |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 368 | "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 Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 385 | }, |
| 386 | }) |
| 387 | |
| 388 | if meErr.GetError() != nil { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 389 | omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error()) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 390 | return nil |
| 391 | } |
| 392 | |
| 393 | return &omci.GetResponse{ |
| 394 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 395 | EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID, |
| 396 | EntityInstance: entityID, |
| 397 | }, |
| 398 | Attributes: managedEntity.GetAttributeValueMap(), |
| 399 | AttributeMask: attributeMask, |
| 400 | Result: me.Success, |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 405 | 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 Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 433 | 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 | |
| 444 | func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 445 | 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 Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 473 | return &omci.GetResponse{ |
| 474 | MeBasePacket: omci.MeBasePacket{ |
| 475 | EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID, |
| 476 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 477 | }, |
| 478 | Attributes: managedEntity.GetAttributeValueMap(), |
| 479 | AttributeMask: attributeMask, |
| 480 | Result: me.Success, |
| 481 | } |
| 482 | } |
| 483 | |
Girish Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 484 | func 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 | |
| 518 | func 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 Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 538 | 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 Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 549 | func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 550 | managedEntity, meErr := me.NewOnuData(me.ParamData{ |
| 551 | EntityID: entityID, |
| 552 | Attributes: me.AttributeValueMap{ |
| 553 | "ManagedEntityId": entityID, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 554 | "MibDataSync": mds, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 555 | }, |
| 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 Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 565 | EntityClass: me.OnuDataClassID, |
| 566 | EntityInstance: entityID, |
| 567 | }, |
| 568 | Attributes: managedEntity.GetAttributeValueMap(), |
| 569 | AttributeMask: attributeMask, |
| 570 | Result: me.Success, |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | func 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 Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 607 | }, |
| 608 | Attributes: managedEntity.GetAttributeValueMap(), |
| 609 | AttributeMask: attributeMask, |
| 610 | Result: me.Success, |
| 611 | } |
| 612 | } |
| 613 | |
Himani Chawla | 6bd190a | 2021-07-09 15:31:01 +0530 | [diff] [blame] | 614 | func 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 Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 657 | func ToOctets(str string, size int) []byte { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 658 | 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 | } |