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" |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 23 | "math/rand" |
| 24 | "strconv" |
| 25 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 26 | "github.com/google/gopacket" |
Andrea Campanella | 10426e2 | 2021-10-15 17:58:04 +0200 | [diff] [blame] | 27 | "github.com/opencord/omci-lib-go/v2" |
| 28 | me "github.com/opencord/omci-lib-go/v2/generated" |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/v5/go/openolt" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 30 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | func ParseGetRequest(omciPkt gopacket.Packet) (*omci.GetRequest, error) { |
| 34 | msgLayer := omciPkt.Layer(omci.LayerTypeGetRequest) |
| 35 | if msgLayer == nil { |
| 36 | err := "omci Msg layer could not be detected for LayerTypeGetRequest" |
| 37 | omciLogger.Error(err) |
| 38 | return nil, errors.New(err) |
| 39 | } |
| 40 | msgObj, msgOk := msgLayer.(*omci.GetRequest) |
| 41 | if !msgOk { |
| 42 | err := "omci Msg layer could not be assigned for LayerTypeGetRequest" |
| 43 | omciLogger.Error(err) |
| 44 | return nil, errors.New(err) |
| 45 | } |
| 46 | return msgObj, nil |
| 47 | } |
| 48 | |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 49 | func CreateGetResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, onuSn *openolt.SerialNumber, mds uint8, |
| 50 | activeImageEntityId uint16, committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string, |
| 51 | committedImageVersion string, onuDown bool) ([]byte, error) { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 52 | msgObj, err := ParseGetRequest(omciPkt) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 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 | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 69 | response = createSoftwareImageResponse(msgObj.AttributeMask, msgObj.EntityInstance, |
| 70 | activeImageEntityId, committedImageEntityId, standbyImageVersion, activeImageVersion, committedImageVersion) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 71 | case me.IpHostConfigDataClassID: |
| 72 | response = createIpHostResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 73 | case me.VoipConfigDataClassID: |
| 74 | response = createVoipConfigDataResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 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: |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 78 | response = createPptpEthernetResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown) |
| 79 | case me.PhysicalPathTerminationPointPotsUniClassID: |
| 80 | response = createPptpPotsResponse(msgObj.AttributeMask, msgObj.EntityInstance, onuDown) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 81 | case me.AniGClassID: |
| 82 | response = createAnigResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 83 | case me.OnuDataClassID: |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 84 | response = createOnuDataResponse(msgObj.AttributeMask, msgObj.EntityInstance, mds) |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 85 | case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID: |
| 86 | response = createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 87 | case me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID: |
| 88 | response = createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 89 | case me.EthernetPerformanceMonitoringHistoryDataClassID: |
| 90 | response = createEthernetPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
Girish Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 91 | case me.FecPerformanceMonitoringHistoryDataClassID: |
| 92 | response = createFecPerformanceMonitoringHistoryDataResponse(msgObj.AttributeMask, msgObj.EntityInstance) |
| 93 | case me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID: |
| 94 | response = createGemPortNetworkCtpPerformanceMonitoringHistoryData(msgObj.AttributeMask, msgObj.EntityInstance) |
Himani Chawla | 6bd190a | 2021-07-09 15:31:01 +0530 | [diff] [blame] | 95 | case me.EthernetFrameExtendedPmClassID, |
| 96 | me.EthernetFrameExtendedPm64BitClassID: |
| 97 | response = createEthernetFrameExtendedPmGetResponse(msgObj.EntityClass, msgObj.AttributeMask, msgObj.EntityInstance) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 98 | default: |
| 99 | omciLogger.WithFields(log.Fields{ |
| 100 | "EntityClass": msgObj.EntityClass, |
| 101 | "EntityInstance": msgObj.EntityInstance, |
| 102 | "AttributeMask": fmt.Sprintf("%x", msgObj.AttributeMask), |
| 103 | }).Warnf("do-not-know-how-to-handle-get-request-for-me-class") |
| 104 | return nil, nil |
| 105 | } |
| 106 | |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 107 | pkt, err := Serialize(omci.GetResponseType, response, omciMsg.TransactionID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 108 | if err != nil { |
| 109 | omciLogger.WithFields(log.Fields{ |
| 110 | "Err": err, |
| 111 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
Matteo Scandolo | 78d5ee1 | 2021-04-14 11:11:32 -0700 | [diff] [blame] | 112 | }).Error("cannot-Serialize-GetResponse") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 113 | return nil, err |
| 114 | } |
| 115 | |
| 116 | log.WithFields(log.Fields{ |
| 117 | "TxID": strconv.FormatInt(int64(omciMsg.TransactionID), 16), |
| 118 | "pkt": hex.EncodeToString(pkt), |
| 119 | }).Trace("omci-get-response") |
| 120 | |
| 121 | return pkt, nil |
| 122 | } |
| 123 | |
| 124 | func createOnu2gResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 125 | |
| 126 | managedEntity, meErr := me.NewOnu2G(me.ParamData{ |
| 127 | EntityID: entityID, |
| 128 | Attributes: me.AttributeValueMap{ |
| 129 | "ManagedEntityId": entityID, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 130 | "EquipmentId": ToOctets("12345123451234512345", 20), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 131 | "OpticalNetworkUnitManagementAndControlChannelOmccVersion": 180, |
| 132 | "VendorProductCode": 0, |
| 133 | "SecurityCapability": 1, |
| 134 | "SecurityMode": 1, |
| 135 | "TotalPriorityQueueNumber": 1, |
| 136 | "TotalTrafficSchedulerNumber": 1, |
| 137 | "Deprecated": 1, |
| 138 | "TotalGemPortIdNumber": 32, |
| 139 | "Sysuptime": 319389947, // NOTE need to be smarter? |
| 140 | "ConnectivityCapability": 127, |
| 141 | "CurrentConnectivityMode": 5, |
| 142 | "QualityOfServiceQosConfigurationFlexibility": 48, |
| 143 | "PriorityQueueScaleFactor": 1, |
| 144 | }, |
| 145 | }) |
| 146 | |
| 147 | if meErr.GetError() != nil { |
| 148 | omciLogger.Errorf("NewOnu2G %v", meErr.Error()) |
| 149 | return nil |
| 150 | } |
| 151 | |
| 152 | return &omci.GetResponse{ |
| 153 | MeBasePacket: omci.MeBasePacket{ |
| 154 | EntityClass: me.Onu2GClassID, |
| 155 | }, |
| 156 | Attributes: managedEntity.GetAttributeValueMap(), |
| 157 | AttributeMask: attributeMask, |
| 158 | Result: me.Success, |
| 159 | } |
| 160 | } |
| 161 | |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 162 | func createOnugResponse(attributeMask uint16, entityID uint16, onuSn *openolt.SerialNumber) *omci.GetResponse { |
| 163 | |
| 164 | managedEntity, meErr := me.NewOnuG(me.ParamData{ |
| 165 | EntityID: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 166 | Attributes: me.AttributeValueMap{ |
| 167 | "ManagedEntityId": entityID, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 168 | "VendorId": ToOctets("BBSM", 4), |
| 169 | "Version": ToOctets("v0.0.1", 14), |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 170 | "SerialNumber": append(onuSn.VendorId, onuSn.VendorSpecific...), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 171 | "TrafficManagementOption": 0, |
| 172 | "Deprecated": 0, |
| 173 | "BatteryBackup": 0, |
| 174 | "AdministrativeState": 0, |
| 175 | "OperationalState": 0, |
| 176 | "OnuSurvivalTime": 10, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 177 | "LogicalOnuId": ToOctets("BBSM", 24), |
| 178 | "LogicalPassword": ToOctets("BBSM", 12), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 179 | "CredentialsStatus": 0, |
| 180 | "ExtendedTcLayerOptions": 0, |
| 181 | }, |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 182 | }) |
| 183 | |
| 184 | if meErr.GetError() != nil { |
| 185 | omciLogger.Errorf("NewOnu2G %v", meErr.Error()) |
| 186 | return nil |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 187 | } |
Matteo Scandolo | 5863f00 | 2021-02-08 08:08:14 -0800 | [diff] [blame] | 188 | |
| 189 | return &omci.GetResponse{ |
| 190 | MeBasePacket: omci.MeBasePacket{ |
| 191 | EntityClass: me.OnuGClassID, |
| 192 | }, |
| 193 | Attributes: managedEntity.GetAttributeValueMap(), |
| 194 | AttributeMask: attributeMask, |
| 195 | Result: me.Success, |
| 196 | } |
| 197 | |
| 198 | //return &omci.GetResponse{ |
| 199 | // MeBasePacket: omci.MeBasePacket{ |
| 200 | // EntityClass: me.OnuGClassID, |
| 201 | // EntityInstance: entityID, |
| 202 | // }, |
| 203 | // Attributes: me.AttributeValueMap{ |
| 204 | // |
| 205 | // }, |
| 206 | // Result: me.Success, |
| 207 | // AttributeMask: attributeMask, |
| 208 | //} |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 211 | func createSoftwareImageResponse(attributeMask uint16, entityInstance uint16, activeImageEntityId uint16, |
| 212 | committedImageEntityId uint16, standbyImageVersion string, activeImageVersion string, committedImageVersion string) *omci.GetResponse { |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 213 | |
| 214 | omciLogger.WithFields(log.Fields{ |
| 215 | "EntityInstance": entityInstance, |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 216 | "AttributeMask": attributeMask, |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 217 | }).Trace("received-get-software-image-request") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 218 | |
| 219 | // Only one image can be active and committed |
| 220 | committed := 0 |
| 221 | active := 0 |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 222 | version := standbyImageVersion |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 223 | if entityInstance == activeImageEntityId { |
| 224 | active = 1 |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 225 | version = activeImageVersion |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 226 | } |
| 227 | if entityInstance == committedImageEntityId { |
| 228 | committed = 1 |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 229 | version = committedImageVersion |
| 230 | } |
| 231 | |
| 232 | imageHash, err := hex.DecodeString(hex.EncodeToString([]byte(version))) |
| 233 | if err != nil { |
| 234 | omciLogger.WithFields(log.Fields{ |
| 235 | "entityId": entityInstance, |
| 236 | "active": active, |
| 237 | "committed": committed, |
| 238 | "err": err, |
| 239 | }).Error("cannot-generate-image-hash") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 242 | // 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] | 243 | res := &omci.GetResponse{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 244 | MeBasePacket: omci.MeBasePacket{ |
| 245 | EntityClass: me.SoftwareImageClassID, |
| 246 | EntityInstance: entityInstance, |
| 247 | }, |
| 248 | Attributes: me.AttributeValueMap{ |
| 249 | "ManagedEntityId": 0, |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 250 | "Version": ToOctets(version, 14), |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 251 | "IsCommitted": committed, |
| 252 | "IsActive": active, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 253 | "IsValid": 1, |
Matteo Scandolo | c00e97a | 2021-05-27 11:45:27 -0700 | [diff] [blame] | 254 | "ProductCode": ToOctets("BBSIM-ONU", 25), |
| 255 | "ImageHash": imageHash, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 256 | }, |
| 257 | Result: me.Success, |
| 258 | AttributeMask: attributeMask, |
| 259 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 260 | |
| 261 | omciLogger.WithFields(log.Fields{ |
| 262 | "omciMessage": res, |
| 263 | "entityId": entityInstance, |
| 264 | "active": active, |
| 265 | "committed": committed, |
Matteo Scandolo | 21195d6 | 2021-04-07 14:31:23 -0700 | [diff] [blame] | 266 | }).Trace("Reporting SoftwareImage") |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 267 | |
| 268 | return res |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | func createIpHostResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse { |
| 272 | return &omci.GetResponse{ |
| 273 | MeBasePacket: omci.MeBasePacket{ |
| 274 | EntityClass: me.IpHostConfigDataClassID, |
| 275 | EntityInstance: entityInstance, |
| 276 | }, |
| 277 | Attributes: me.AttributeValueMap{ |
| 278 | "ManagedEntityId": 0, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 279 | "MacAddress": ToOctets("aabbcc", 6), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 280 | }, |
| 281 | Result: me.Success, |
| 282 | AttributeMask: attributeMask, |
| 283 | } |
| 284 | } |
| 285 | |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 286 | func createVoipConfigDataResponse(attributeMask uint16, entityInstance uint16) *omci.GetResponse { |
| 287 | return &omci.GetResponse{ |
| 288 | MeBasePacket: omci.MeBasePacket{ |
| 289 | EntityClass: me.VoipConfigDataClassID, |
| 290 | EntityInstance: entityInstance, |
| 291 | }, |
| 292 | Attributes: me.AttributeValueMap{ |
| 293 | "ManagedEntityId": 0, |
| 294 | "AvailableSignallingProtocols": 1, |
| 295 | "SignallingProtocolUsed": 1, |
| 296 | "AvailableVoipConfigurationMethods": 1, |
| 297 | "VoipConfigurationMethodUsed": 1, |
| 298 | "VoipConfigurationAddressPointer": 0xFFFF, |
| 299 | "VoipConfigurationState": 0, |
| 300 | "RetrieveProfile": 0, |
| 301 | "ProfileVersion": 0, |
| 302 | }, |
| 303 | Result: me.Success, |
| 304 | AttributeMask: attributeMask, |
| 305 | } |
| 306 | } |
| 307 | |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 308 | func createUnigResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse { |
| 309 | // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks) |
| 310 | omciAdminState := 1 |
| 311 | if !onuDown { |
| 312 | omciAdminState = 0 |
| 313 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 314 | managedEntity, meErr := me.NewUniG(me.ParamData{ |
| 315 | EntityID: entityID, |
| 316 | Attributes: me.AttributeValueMap{ |
| 317 | "ManagedEntityId": entityID, |
| 318 | "Deprecated": 0, |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 319 | "AdministrativeState": omciAdminState, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 320 | "ManagementCapability": 0, |
| 321 | "NonOmciManagementIdentifier": 1, |
| 322 | "RelayAgentOptions": 1, |
| 323 | }, |
| 324 | }) |
| 325 | |
| 326 | if meErr.GetError() != nil { |
| 327 | omciLogger.Errorf("NewUniG %v", meErr.Error()) |
| 328 | return nil |
| 329 | } |
| 330 | |
| 331 | return &omci.GetResponse{ |
| 332 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | c3fd50c | 2021-03-12 16:14:44 -0800 | [diff] [blame] | 333 | EntityClass: me.UniGClassID, |
| 334 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 335 | }, |
| 336 | Attributes: managedEntity.GetAttributeValueMap(), |
| 337 | AttributeMask: attributeMask, |
| 338 | Result: me.Success, |
| 339 | } |
| 340 | } |
| 341 | |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 342 | func createPptpEthernetResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse { |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 343 | // Valid values for oper_state are 0 (enabled) and 1 (disabled) |
| 344 | // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks) |
| 345 | onuAdminState := 1 |
| 346 | if !onuDown { |
| 347 | onuAdminState = 0 |
| 348 | } |
| 349 | onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 350 | managedEntity, meErr := me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{ |
| 351 | EntityID: entityID, |
| 352 | Attributes: me.AttributeValueMap{ |
| 353 | "ManagedEntityId": entityID, |
| 354 | "ExpectedType": 0, |
| 355 | "SensedType": 0, |
| 356 | "AutoDetectionConfiguration": 0, |
| 357 | "EthernetLoopbackConfiguration": 0, |
Girish Gowdra | 996d81e | 2021-04-21 16:16:27 -0700 | [diff] [blame] | 358 | "AdministrativeState": onuAdminState, |
| 359 | "OperationalState": onuOperState, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 360 | "ConfigurationInd": 0, |
| 361 | "MaxFrameSize": 0, |
| 362 | "DteOrDceInd": 0, |
| 363 | "PauseTime": 0, |
| 364 | "BridgedOrIpInd": 0, |
| 365 | "Arc": 0, |
| 366 | "ArcInterval": 0, |
| 367 | "PppoeFilter": 0, |
| 368 | "PowerControl": 0, |
| 369 | }, |
| 370 | }) |
| 371 | |
| 372 | if meErr.GetError() != nil { |
| 373 | omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error()) |
| 374 | return nil |
| 375 | } |
| 376 | |
| 377 | return &omci.GetResponse{ |
| 378 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | c3fd50c | 2021-03-12 16:14:44 -0800 | [diff] [blame] | 379 | EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 380 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 381 | }, |
| 382 | Attributes: managedEntity.GetAttributeValueMap(), |
| 383 | AttributeMask: attributeMask, |
| 384 | Result: me.Success, |
| 385 | } |
| 386 | } |
| 387 | |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 388 | func createPptpPotsResponse(attributeMask uint16, entityID uint16, onuDown bool) *omci.GetResponse { |
| 389 | // Valid values for oper_state are 0 (enabled) and 1 (disabled) |
| 390 | // Valid values for uni_admin_state are 0 (unlocks) and 1 (locks) |
| 391 | onuAdminState := 1 |
| 392 | if !onuDown { |
| 393 | onuAdminState = 0 |
| 394 | } |
| 395 | onuOperState := onuAdminState // For now make the assumption that oper state reflects the admin state |
| 396 | managedEntity, meErr := me.NewPhysicalPathTerminationPointPotsUni(me.ParamData{ |
| 397 | EntityID: entityID, |
| 398 | Attributes: me.AttributeValueMap{ |
| 399 | "ManagedEntityId": entityID, |
| 400 | "AdministrativeState": onuAdminState, |
| 401 | "Deprecated": 0, |
| 402 | "Arc": 0, |
| 403 | "ArcInterval": 0, |
| 404 | "Impedance": 0, |
| 405 | "TransmissionPath": 0, |
| 406 | "RxGain": 0, |
| 407 | "TxGain": 0, |
| 408 | "OperationalState": onuOperState, |
| 409 | "HookState": 0, |
| 410 | "PotsHoldoverTime": 0, |
| 411 | "NominalFeedVoltage": 0, |
| 412 | "LossOfSoftswitch": 0, |
| 413 | }, |
| 414 | }) |
| 415 | |
| 416 | if meErr.GetError() != nil { |
| 417 | omciLogger.Errorf("NewPhysicalPathTerminationPointPotsUni %v", meErr.Error()) |
| 418 | return nil |
| 419 | } |
| 420 | |
| 421 | return &omci.GetResponse{ |
| 422 | MeBasePacket: omci.MeBasePacket{ |
| 423 | EntityClass: me.PhysicalPathTerminationPointPotsUniClassID, |
| 424 | EntityInstance: entityID, |
| 425 | }, |
| 426 | Attributes: managedEntity.GetAttributeValueMap(), |
| 427 | AttributeMask: attributeMask, |
| 428 | Result: me.Success, |
| 429 | } |
| 430 | } |
| 431 | |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 432 | func createEthernetFramePerformanceMonitoringHistoryDataUpstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 433 | managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(me.ParamData{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 434 | EntityID: entityID, |
| 435 | Attributes: me.AttributeValueMap{ |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 436 | "ManagedEntityId": entityID, |
| 437 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 438 | "ThresholdData12Id": 0, |
| 439 | "DropEvents": rand.Intn(100), |
| 440 | "Octets": rand.Intn(100), |
| 441 | "Packets": rand.Intn(100), |
| 442 | "BroadcastPackets": rand.Intn(100), |
| 443 | "MulticastPackets": rand.Intn(100), |
| 444 | "CrcErroredPackets": rand.Intn(100), |
| 445 | "UndersizePackets": rand.Intn(100), |
| 446 | "OversizePackets": rand.Intn(100), |
| 447 | "Packets64Octets": rand.Intn(100), |
| 448 | "Packets65To127Octets": rand.Intn(100), |
| 449 | "Packets128To255Octets": rand.Intn(100), |
| 450 | "Packets256To511Octets": rand.Intn(100), |
| 451 | "Packets512To1023Octets": rand.Intn(100), |
| 452 | "Packets1024To1518Octets": rand.Intn(100), |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 453 | }, |
| 454 | }) |
| 455 | |
| 456 | if meErr.GetError() != nil { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 457 | omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataUpstream %v", meErr.Error()) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 458 | return nil |
| 459 | } |
| 460 | |
| 461 | return &omci.GetResponse{ |
| 462 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 463 | EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID, |
| 464 | EntityInstance: entityID, |
| 465 | }, |
| 466 | Attributes: managedEntity.GetAttributeValueMap(), |
| 467 | AttributeMask: attributeMask, |
| 468 | Result: me.Success, |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | func createEthernetFramePerformanceMonitoringHistoryDataDownstreamResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 473 | managedEntity, meErr := me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(me.ParamData{ |
| 474 | EntityID: entityID, |
| 475 | Attributes: me.AttributeValueMap{ |
| 476 | "ManagedEntityId": entityID, |
| 477 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 478 | "ThresholdData12Id": 0, |
| 479 | "DropEvents": rand.Intn(100), |
| 480 | "Octets": rand.Intn(100), |
| 481 | "Packets": rand.Intn(100), |
| 482 | "BroadcastPackets": rand.Intn(100), |
| 483 | "MulticastPackets": rand.Intn(100), |
| 484 | "CrcErroredPackets": rand.Intn(100), |
| 485 | "UndersizePackets": rand.Intn(100), |
| 486 | "OversizePackets": rand.Intn(100), |
| 487 | "Packets64Octets": rand.Intn(100), |
| 488 | "Packets65To127Octets": rand.Intn(100), |
| 489 | "Packets128To255Octets": rand.Intn(100), |
| 490 | "Packets256To511Octets": rand.Intn(100), |
| 491 | "Packets512To1023Octets": rand.Intn(100), |
| 492 | "Packets1024To1518Octets": rand.Intn(100), |
| 493 | }, |
| 494 | }) |
| 495 | |
| 496 | if meErr.GetError() != nil { |
| 497 | omciLogger.Errorf("NewEthernetFramePerformanceMonitoringHistoryDataDownstream %v", meErr.Error()) |
| 498 | return nil |
| 499 | } |
| 500 | |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 501 | return &omci.GetResponse{ |
| 502 | MeBasePacket: omci.MeBasePacket{ |
| 503 | EntityClass: me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID, |
| 504 | EntityInstance: entityID, |
| 505 | }, |
| 506 | Attributes: managedEntity.GetAttributeValueMap(), |
| 507 | AttributeMask: attributeMask, |
| 508 | Result: me.Success, |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | func createEthernetPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 513 | managedEntity, meErr := me.NewEthernetPerformanceMonitoringHistoryData(me.ParamData{ |
| 514 | EntityID: entityID, |
| 515 | Attributes: me.AttributeValueMap{ |
| 516 | "ManagedEntityId": entityID, |
| 517 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 518 | "ThresholdData12Id": 0, |
| 519 | "FcsErrors": rand.Intn(100), |
| 520 | "ExcessiveCollisionCounter": rand.Intn(100), |
| 521 | "LateCollisionCounter": rand.Intn(100), |
| 522 | "FramesTooLong": rand.Intn(100), |
| 523 | "BufferOverflowsOnReceive": rand.Intn(100), |
| 524 | "BufferOverflowsOnTransmit": rand.Intn(100), |
| 525 | "SingleCollisionFrameCounter": rand.Intn(100), |
| 526 | "MultipleCollisionsFrameCounter": rand.Intn(100), |
| 527 | "SqeCounter": rand.Intn(100), |
| 528 | "DeferredTransmissionCounter": rand.Intn(100), |
| 529 | "InternalMacTransmitErrorCounter": rand.Intn(100), |
| 530 | "CarrierSenseErrorCounter": rand.Intn(100), |
| 531 | "AlignmentErrorCounter": rand.Intn(100), |
| 532 | "InternalMacReceiveErrorCounter": rand.Intn(100), |
| 533 | }, |
| 534 | }) |
| 535 | |
| 536 | if meErr.GetError() != nil { |
| 537 | omciLogger.Errorf("NewEthernetPerformanceMonitoringHistoryData %v", meErr.Error()) |
| 538 | return nil |
| 539 | } |
| 540 | |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 541 | return &omci.GetResponse{ |
| 542 | MeBasePacket: omci.MeBasePacket{ |
| 543 | EntityClass: me.EthernetPerformanceMonitoringHistoryDataClassID, |
| 544 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 545 | }, |
| 546 | Attributes: managedEntity.GetAttributeValueMap(), |
| 547 | AttributeMask: attributeMask, |
| 548 | Result: me.Success, |
| 549 | } |
| 550 | } |
| 551 | |
Girish Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 552 | func createFecPerformanceMonitoringHistoryDataResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 553 | managedEntity, meErr := me.NewFecPerformanceMonitoringHistoryData(me.ParamData{ |
| 554 | EntityID: entityID, |
| 555 | Attributes: me.AttributeValueMap{ |
| 556 | "ManagedEntityId": entityID, |
| 557 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 558 | "ThresholdData12Id": 0, |
| 559 | "CorrectedBytes": rand.Intn(100), |
| 560 | "CorrectedCodeWords": rand.Intn(100), |
| 561 | "UncorrectableCodeWords": rand.Intn(100), |
| 562 | "TotalCodeWords": rand.Intn(100), |
| 563 | "FecSeconds": rand.Intn(100), |
| 564 | }, |
| 565 | }) |
| 566 | |
| 567 | if meErr.GetError() != nil { |
| 568 | omciLogger.Errorf("NewFecPerformanceMonitoringHistoryData %v", meErr.Error()) |
| 569 | return nil |
| 570 | } |
| 571 | |
| 572 | // FEC History counter fits within single gem payload. |
| 573 | // No need of the logical we use in other Ethernet History counters or Gem Port History counters |
| 574 | |
| 575 | return &omci.GetResponse{ |
| 576 | MeBasePacket: omci.MeBasePacket{ |
| 577 | EntityClass: me.FecPerformanceMonitoringHistoryDataClassID, |
| 578 | EntityInstance: entityID, |
| 579 | }, |
| 580 | Attributes: managedEntity.GetAttributeValueMap(), |
| 581 | AttributeMask: attributeMask, |
| 582 | Result: me.Success, |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | func createGemPortNetworkCtpPerformanceMonitoringHistoryData(attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 587 | managedEntity, meErr := me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(me.ParamData{ |
| 588 | EntityID: entityID, |
| 589 | Attributes: me.AttributeValueMap{ |
| 590 | "ManagedEntityId": entityID, |
| 591 | "IntervalEndTime": 0, // This ideally should increment by 1 every collection interval, but staying 0 for simulation is Ok for now. |
| 592 | "ThresholdData12Id": 0, |
| 593 | "TransmittedGemFrames": rand.Intn(100), |
| 594 | "ReceivedGemFrames": rand.Intn(100), |
| 595 | "ReceivedPayloadBytes": rand.Intn(100), |
| 596 | "TransmittedPayloadBytes": rand.Intn(100), |
| 597 | "EncryptionKeyErrors": rand.Intn(100), |
| 598 | }, |
| 599 | }) |
| 600 | |
| 601 | if meErr.GetError() != nil { |
| 602 | omciLogger.Errorf("NewGemPortNetworkCtpPerformanceMonitoringHistoryData %v", meErr.Error()) |
| 603 | return nil |
| 604 | } |
| 605 | |
Girish Gowdra | 6d9a1a4 | 2021-03-05 16:07:15 -0800 | [diff] [blame] | 606 | return &omci.GetResponse{ |
| 607 | MeBasePacket: omci.MeBasePacket{ |
| 608 | EntityClass: me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID, |
| 609 | EntityInstance: entityID, |
| 610 | }, |
| 611 | Attributes: managedEntity.GetAttributeValueMap(), |
| 612 | AttributeMask: attributeMask, |
| 613 | Result: me.Success, |
| 614 | } |
| 615 | } |
| 616 | |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 617 | func createOnuDataResponse(attributeMask uint16, entityID uint16, mds uint8) *omci.GetResponse { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 618 | managedEntity, meErr := me.NewOnuData(me.ParamData{ |
| 619 | EntityID: entityID, |
| 620 | Attributes: me.AttributeValueMap{ |
| 621 | "ManagedEntityId": entityID, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 622 | "MibDataSync": mds, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 623 | }, |
| 624 | }) |
| 625 | |
| 626 | if meErr.GetError() != nil { |
| 627 | omciLogger.Errorf("NewOnuData %v", meErr.Error()) |
| 628 | return nil |
| 629 | } |
| 630 | |
| 631 | return &omci.GetResponse{ |
| 632 | MeBasePacket: omci.MeBasePacket{ |
Girish Gowdra | a539f52 | 2021-02-15 23:00:45 -0800 | [diff] [blame] | 633 | EntityClass: me.OnuDataClassID, |
| 634 | EntityInstance: entityID, |
| 635 | }, |
| 636 | Attributes: managedEntity.GetAttributeValueMap(), |
| 637 | AttributeMask: attributeMask, |
| 638 | Result: me.Success, |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | func createAnigResponse(attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 643 | managedEntity, meErr := me.NewAniG(me.ParamData{ |
| 644 | EntityID: entityID, |
| 645 | Attributes: me.AttributeValueMap{ |
| 646 | "ManagedEntityId": entityID, |
| 647 | "SrIndication": 0, |
| 648 | "TotalTcontNumber": 0, |
| 649 | "GemBlockLength": 0, |
| 650 | "PiggybackDbaReporting": 0, |
| 651 | "Deprecated": 0, |
| 652 | "SignalFailThreshold": 0, |
| 653 | "SignalDegradeThreshold": 0, |
| 654 | "Arc": 0, |
| 655 | "ArcInterval": 0, |
| 656 | "OpticalSignalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0 |
| 657 | "LowerOpticalThreshold": 0, |
| 658 | "UpperOpticalThreshold": 0, |
| 659 | "OnuResponseTime": 0, |
| 660 | "TransmitOpticalLevel": rand.Intn(16000), // generate some random power level than defaulting to 0 |
| 661 | "LowerTransmitPowerThreshold": 0, |
| 662 | "UpperTransmitPowerThreshold": 0, |
| 663 | }, |
| 664 | }) |
| 665 | |
| 666 | if meErr.GetError() != nil { |
| 667 | omciLogger.Errorf("NewAniG %v", meErr.Error()) |
| 668 | return nil |
| 669 | } |
| 670 | |
| 671 | return &omci.GetResponse{ |
| 672 | MeBasePacket: omci.MeBasePacket{ |
| 673 | EntityClass: me.AniGClassID, |
| 674 | EntityInstance: entityID, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 675 | }, |
| 676 | Attributes: managedEntity.GetAttributeValueMap(), |
| 677 | AttributeMask: attributeMask, |
| 678 | Result: me.Success, |
| 679 | } |
| 680 | } |
| 681 | |
Himani Chawla | 6bd190a | 2021-07-09 15:31:01 +0530 | [diff] [blame] | 682 | func createEthernetFrameExtendedPmGetResponse(meClass me.ClassID, attributeMask uint16, entityID uint16) *omci.GetResponse { |
| 683 | |
| 684 | callback := me.NewEthernetFrameExtendedPm |
| 685 | if meClass != me.EthernetFrameExtendedPmClassID { |
| 686 | callback = me.NewEthernetFrameExtendedPm64Bit |
| 687 | } |
Himani Chawla | 908a1f5 | 2022-01-27 14:39:44 +0530 | [diff] [blame] | 688 | attr := me.AttributeValueMap{ |
| 689 | "ManagedEntityId": entityID, |
| 690 | "DropEvents": 100, |
| 691 | "Octets": 101, |
| 692 | "Frames": 102, |
| 693 | "BroadcastFrames": 103, |
| 694 | "MulticastFrames": 104, |
| 695 | "CrcErroredFrames": 105, |
| 696 | "UndersizeFrames": 106, |
| 697 | "OversizeFrames": 107, |
| 698 | "Frames64Octets": 108, |
| 699 | "Frames65To127Octets": 109, |
| 700 | "Frames128To255Octets": 110, |
| 701 | "Frames256To511Octets": 111, |
| 702 | "Frames512To1023Octets": 112, |
| 703 | "Frames1024To1518Octets": 113, |
| 704 | } |
Himani Chawla | 6bd190a | 2021-07-09 15:31:01 +0530 | [diff] [blame] | 705 | managedEntity, meErr := callback(me.ParamData{ |
Himani Chawla | 908a1f5 | 2022-01-27 14:39:44 +0530 | [diff] [blame] | 706 | EntityID: entityID, |
| 707 | Attributes: attr, |
Himani Chawla | 6bd190a | 2021-07-09 15:31:01 +0530 | [diff] [blame] | 708 | }) |
| 709 | |
| 710 | if meErr.GetError() != nil { |
| 711 | omciLogger.Errorf("NewEthernetFrameExtendedPm %v", meErr.Error()) |
| 712 | return nil |
| 713 | } |
| 714 | |
| 715 | return &omci.GetResponse{ |
| 716 | MeBasePacket: omci.MeBasePacket{ |
| 717 | EntityClass: meClass, |
| 718 | EntityInstance: entityID, |
| 719 | }, |
| 720 | Attributes: managedEntity.GetAttributeValueMap(), |
| 721 | AttributeMask: attributeMask, |
| 722 | Result: me.Success, |
| 723 | } |
| 724 | } |
| 725 | |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 726 | func ToOctets(str string, size int) []byte { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 727 | asciiBytes := []byte(str) |
| 728 | |
| 729 | if len(asciiBytes) < size { |
| 730 | missing := size - len(asciiBytes) |
| 731 | for i := 0; i < missing; i++ { |
| 732 | asciiBytes = append(asciiBytes, []byte{0x00}[0]) |
| 733 | } |
| 734 | } |
| 735 | return asciiBytes |
| 736 | } |