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