Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
| 3 | * Copyright 2020-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package omci |
| 19 | |
| 20 | import ( |
| 21 | "encoding/binary" |
| 22 | "errors" |
| 23 | "fmt" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 24 | "github.com/google/gopacket" |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 25 | me "github.com/opencord/omci-lib-go/generated" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | // MessageType is the OMCI Message Type or'ed with the AR/AK flags as appropriate. |
| 29 | type MessageType byte |
| 30 | |
| 31 | const ( |
Girish Gowdra | 8a7b456 | 2021-02-23 16:27:42 -0800 | [diff] [blame] | 32 | CreateRequestType = MessageType(byte(me.Create) | me.AR) |
| 33 | CreateResponseType = MessageType(byte(me.Create) | me.AK) |
| 34 | DeleteRequestType = MessageType(byte(me.Delete) | me.AR) |
| 35 | DeleteResponseType = MessageType(byte(me.Delete) | me.AK) |
| 36 | SetRequestType = MessageType(byte(me.Set) | me.AR) |
| 37 | SetResponseType = MessageType(byte(me.Set) | me.AK) |
| 38 | GetRequestType = MessageType(byte(me.Get) | me.AR) |
| 39 | GetResponseType = MessageType(byte(me.Get) | me.AK) |
| 40 | GetAllAlarmsRequestType = MessageType(byte(me.GetAllAlarms) | me.AR) |
| 41 | GetAllAlarmsResponseType = MessageType(byte(me.GetAllAlarms) | me.AK) |
| 42 | GetAllAlarmsNextRequestType = MessageType(byte(me.GetAllAlarmsNext) | me.AR) |
| 43 | GetAllAlarmsNextResponseType = MessageType(byte(me.GetAllAlarmsNext) | me.AK) |
| 44 | MibUploadRequestType = MessageType(byte(me.MibUpload) | me.AR) |
| 45 | MibUploadResponseType = MessageType(byte(me.MibUpload) | me.AK) |
| 46 | MibUploadNextRequestType = MessageType(byte(me.MibUploadNext) | me.AR) |
| 47 | MibUploadNextResponseType = MessageType(byte(me.MibUploadNext) | me.AK) |
| 48 | MibResetRequestType = MessageType(byte(me.MibReset) | me.AR) |
| 49 | MibResetResponseType = MessageType(byte(me.MibReset) | me.AK) |
| 50 | TestRequestType = MessageType(byte(me.Test) | me.AR) |
| 51 | TestResponseType = MessageType(byte(me.Test) | me.AK) |
| 52 | StartSoftwareDownloadRequestType = MessageType(byte(me.StartSoftwareDownload) | me.AR) |
| 53 | StartSoftwareDownloadResponseType = MessageType(byte(me.StartSoftwareDownload) | me.AK) |
| 54 | DownloadSectionRequestType = MessageType(me.DownloadSection) // me.AR is optional |
| 55 | DownloadSectionRequestWithResponseType = MessageType(byte(me.DownloadSection) | me.AR) |
| 56 | DownloadSectionResponseType = MessageType(byte(me.DownloadSection) | me.AK) |
| 57 | EndSoftwareDownloadRequestType = MessageType(byte(me.EndSoftwareDownload) | me.AR) |
| 58 | EndSoftwareDownloadResponseType = MessageType(byte(me.EndSoftwareDownload) | me.AK) |
| 59 | ActivateSoftwareRequestType = MessageType(byte(me.ActivateSoftware) | me.AR) |
| 60 | ActivateSoftwareResponseType = MessageType(byte(me.ActivateSoftware) | me.AK) |
| 61 | CommitSoftwareRequestType = MessageType(byte(me.CommitSoftware) | me.AR) |
| 62 | CommitSoftwareResponseType = MessageType(byte(me.CommitSoftware) | me.AK) |
| 63 | SynchronizeTimeRequestType = MessageType(byte(me.SynchronizeTime) | me.AR) |
| 64 | SynchronizeTimeResponseType = MessageType(byte(me.SynchronizeTime) | me.AK) |
| 65 | RebootRequestType = MessageType(byte(me.Reboot) | me.AR) |
| 66 | RebootResponseType = MessageType(byte(me.Reboot) | me.AK) |
| 67 | GetNextRequestType = MessageType(byte(me.GetNext) | me.AR) |
| 68 | GetNextResponseType = MessageType(byte(me.GetNext) | me.AK) |
| 69 | GetCurrentDataRequestType = MessageType(byte(me.GetCurrentData) | me.AR) |
| 70 | GetCurrentDataResponseType = MessageType(byte(me.GetCurrentData) | me.AK) |
| 71 | SetTableRequestType = MessageType(byte(me.SetTable) | me.AR) |
| 72 | SetTableResponseType = MessageType(byte(me.SetTable) | me.AK) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 73 | // Autonomous ONU messages |
| 74 | AlarmNotificationType = MessageType(byte(me.AlarmNotification)) |
| 75 | AttributeValueChangeType = MessageType(byte(me.AttributeValueChange)) |
| 76 | TestResultType = MessageType(byte(me.TestResult)) |
| 77 | ) |
| 78 | |
| 79 | func (mt MessageType) String() string { |
| 80 | switch mt { |
| 81 | default: |
| 82 | return "Unknown" |
| 83 | |
| 84 | case CreateRequestType: |
| 85 | return "Create Request" |
| 86 | case CreateResponseType: |
| 87 | return "Create Response" |
| 88 | case DeleteRequestType: |
| 89 | return "Delete Request" |
| 90 | case DeleteResponseType: |
| 91 | return "Delete Response" |
| 92 | case SetRequestType: |
| 93 | return "Set Request" |
| 94 | case SetResponseType: |
| 95 | return "Set Response" |
| 96 | case GetRequestType: |
| 97 | return "Get Request" |
| 98 | case GetResponseType: |
| 99 | return "Get Response" |
| 100 | case GetAllAlarmsRequestType: |
| 101 | return "Get All Alarms Request" |
| 102 | case GetAllAlarmsResponseType: |
| 103 | return "Get All Alarms Response" |
| 104 | case GetAllAlarmsNextRequestType: |
| 105 | return "Get All Alarms Next Request" |
| 106 | case GetAllAlarmsNextResponseType: |
| 107 | return "Get All Alarms Next Response" |
| 108 | case MibUploadRequestType: |
| 109 | return "MIB Upload Request" |
| 110 | case MibUploadResponseType: |
| 111 | return "MIB Upload Response" |
| 112 | case MibUploadNextRequestType: |
| 113 | return "MIB Upload Next Request" |
| 114 | case MibUploadNextResponseType: |
| 115 | return "MIB Upload Next Response" |
| 116 | case MibResetRequestType: |
| 117 | return "MIB Reset Request" |
| 118 | case MibResetResponseType: |
| 119 | return "MIB Reset Response" |
| 120 | case TestRequestType: |
| 121 | return "Test Request" |
| 122 | case TestResponseType: |
| 123 | return "Test Response" |
| 124 | case StartSoftwareDownloadRequestType: |
| 125 | return "Start Software Download Request" |
| 126 | case StartSoftwareDownloadResponseType: |
| 127 | return "Start Software Download Response" |
| 128 | case DownloadSectionRequestType: |
| 129 | return "Download Section Request" |
| 130 | case DownloadSectionResponseType: |
| 131 | return "Download Section Response" |
| 132 | case EndSoftwareDownloadRequestType: |
| 133 | return "End Software Download Request" |
| 134 | case EndSoftwareDownloadResponseType: |
| 135 | return "End Software Download Response" |
| 136 | case ActivateSoftwareRequestType: |
| 137 | return "Activate Software Request" |
| 138 | case ActivateSoftwareResponseType: |
| 139 | return "Activate Software Response" |
| 140 | case CommitSoftwareRequestType: |
| 141 | return "Commit Software Request" |
| 142 | case CommitSoftwareResponseType: |
| 143 | return "Commit Software Response" |
| 144 | case SynchronizeTimeRequestType: |
| 145 | return "Synchronize Time Request" |
| 146 | case SynchronizeTimeResponseType: |
| 147 | return "Synchronize Time Response" |
| 148 | case RebootRequestType: |
| 149 | return "Reboot Request" |
| 150 | case RebootResponseType: |
| 151 | return "Reboot Response" |
| 152 | case GetNextRequestType: |
| 153 | return "Get Next Request" |
| 154 | case GetNextResponseType: |
| 155 | return "Get Next Response" |
| 156 | case GetCurrentDataRequestType: |
| 157 | return "Get Current Data Request" |
| 158 | case GetCurrentDataResponseType: |
| 159 | return "Get Current Data Response" |
| 160 | case SetTableRequestType: |
| 161 | return "Set Table Request" |
| 162 | case SetTableResponseType: |
| 163 | return "Set Table Response" |
| 164 | case AlarmNotificationType: |
| 165 | return "Alarm Notification" |
| 166 | case AttributeValueChangeType: |
| 167 | return "Attribute Value Change" |
| 168 | case TestResultType: |
| 169 | return "Test Result" |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | ///////////////////////////////////////////////////////////////////////////// |
| 174 | // CreateRequest |
| 175 | type CreateRequest struct { |
| 176 | MeBasePacket |
| 177 | Attributes me.AttributeValueMap |
| 178 | } |
| 179 | |
| 180 | func (omci *CreateRequest) String() string { |
| 181 | return fmt.Sprintf("%v, attributes: %v", omci.MeBasePacket.String(), omci.Attributes) |
| 182 | } |
| 183 | |
| 184 | // DecodeFromBytes decodes the given bytes of a Create Request into this layer |
| 185 | func (omci *CreateRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 186 | // Common ClassID/EntityID decode in msgBase |
| 187 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 188 | if err != nil { |
| 189 | return err |
| 190 | } |
| 191 | // Create attribute mask for all set-by-create entries |
| 192 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 193 | me.ParamData{EntityID: omci.EntityInstance}) |
| 194 | if omciErr.StatusCode() != me.Success { |
| 195 | return omciErr.GetError() |
| 196 | } |
| 197 | // ME needs to support Create |
| 198 | if !me.SupportsMsgType(meDefinition, me.Create) { |
| 199 | return me.NewProcessingError("managed entity does not support Create Message-Type") |
| 200 | } |
| 201 | var sbcMask uint16 |
| 202 | for index, attr := range meDefinition.GetAttributeDefinitions() { |
| 203 | if me.SupportsAttributeAccess(attr, me.SetByCreate) { |
| 204 | if index == 0 { |
| 205 | continue // Skip Entity ID |
| 206 | } |
| 207 | sbcMask |= attr.Mask |
| 208 | } |
| 209 | } |
| 210 | // Attribute decode |
| 211 | omci.Attributes, err = meDefinition.DecodeAttributes(sbcMask, data[4:], p, byte(CreateRequestType)) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | if eidDef, eidDefOK := meDefinition.GetAttributeDefinitions()[0]; eidDefOK { |
| 216 | omci.Attributes[eidDef.GetName()] = omci.EntityInstance |
| 217 | return nil |
| 218 | } |
| 219 | panic("All Managed Entities have an EntityID attribute") |
| 220 | } |
| 221 | |
| 222 | func decodeCreateRequest(data []byte, p gopacket.PacketBuilder) error { |
| 223 | omci := &CreateRequest{} |
| 224 | omci.MsgLayerType = LayerTypeCreateRequest |
| 225 | return decodingLayerDecoder(omci, data, p) |
| 226 | } |
| 227 | |
| 228 | // SerializeTo provides serialization of an Create Request Message |
| 229 | func (omci *CreateRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 230 | // Basic (common) OMCI Header is 8 octets, 10 |
| 231 | err := omci.MeBasePacket.SerializeTo(b) |
| 232 | if err != nil { |
| 233 | return err |
| 234 | } |
| 235 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 236 | me.ParamData{EntityID: omci.EntityInstance}) |
| 237 | if omciErr.StatusCode() != me.Success { |
| 238 | return omciErr.GetError() |
| 239 | } |
| 240 | // Create attribute mask of SetByCreate attributes that should be present in the provided |
| 241 | // attributes. |
| 242 | var sbcMask uint16 |
| 243 | for index, attr := range meDefinition.GetAttributeDefinitions() { |
| 244 | if me.SupportsAttributeAccess(attr, me.SetByCreate) { |
| 245 | if index == 0 { |
| 246 | continue // Skip Entity ID |
| 247 | } |
| 248 | sbcMask |= attr.Mask |
| 249 | } |
| 250 | } |
| 251 | // Attribute serialization |
| 252 | // TODO: Only Baseline supported at this time |
| 253 | bytesAvailable := MaxBaselineLength - 8 - 8 |
| 254 | err, _ = meDefinition.SerializeAttributes(omci.Attributes, sbcMask, b, byte(CreateRequestType), bytesAvailable, false) |
| 255 | return err |
| 256 | } |
| 257 | |
| 258 | ///////////////////////////////////////////////////////////////////////////// |
| 259 | // CreateResponse |
| 260 | type CreateResponse struct { |
| 261 | MeBasePacket |
| 262 | Result me.Results |
| 263 | AttributeExecutionMask uint16 // Used when Result == ParameterError |
| 264 | } |
| 265 | |
| 266 | func (omci *CreateResponse) String() string { |
| 267 | return fmt.Sprintf("%v, Result: %d (%v), Mask: %#x", |
| 268 | omci.MeBasePacket.String(), omci.Result, omci.Result, omci.AttributeExecutionMask) |
| 269 | } |
| 270 | |
| 271 | // DecodeFromBytes decodes the given bytes of a Create Response into this layer |
| 272 | func (omci *CreateResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 273 | // Common ClassID/EntityID decode in msgBase |
| 274 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 275 | if err != nil { |
| 276 | return err |
| 277 | } |
| 278 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 279 | me.ParamData{EntityID: omci.EntityInstance}) |
| 280 | if omciErr.StatusCode() != me.Success { |
| 281 | return omciErr.GetError() |
| 282 | } |
| 283 | // ME needs to support Create |
| 284 | if !me.SupportsMsgType(entity, me.Create) { |
| 285 | return me.NewProcessingError("managed entity does not support the Create Message-Type") |
| 286 | } |
| 287 | omci.Result = me.Results(data[4]) |
| 288 | if omci.Result == me.ParameterError { |
| 289 | omci.AttributeExecutionMask = binary.BigEndian.Uint16(data[5:]) |
| 290 | // TODO: validation that attributes set in mask are SetByCreate would be good here |
| 291 | } |
| 292 | return nil |
| 293 | } |
| 294 | |
| 295 | func decodeCreateResponse(data []byte, p gopacket.PacketBuilder) error { |
| 296 | omci := &CreateResponse{} |
| 297 | omci.MsgLayerType = LayerTypeCreateResponse |
| 298 | return decodingLayerDecoder(omci, data, p) |
| 299 | } |
| 300 | |
| 301 | // SerializeTo provides serialization of an Create Response message |
| 302 | func (omci *CreateResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 303 | // Basic (common) OMCI Header is 8 octets, 10 |
| 304 | err := omci.MeBasePacket.SerializeTo(b) |
| 305 | if err != nil { |
| 306 | return err |
| 307 | } |
| 308 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 309 | me.ParamData{EntityID: omci.EntityInstance}) |
| 310 | if omciErr.StatusCode() != me.Success { |
| 311 | return omciErr.GetError() |
| 312 | } |
| 313 | // ME needs to support Create |
| 314 | if !me.SupportsMsgType(entity, me.Create) { |
| 315 | return me.NewProcessingError("managed entity does not support the Create Message-Type") |
| 316 | } |
| 317 | bytes, err := b.AppendBytes(3) |
| 318 | if err != nil { |
| 319 | return err |
| 320 | } |
| 321 | bytes[0] = byte(omci.Result) |
| 322 | if omci.Result == me.ParameterError { |
| 323 | // TODO: validation that attributes set in mask are SetByCreate would be good here |
| 324 | binary.BigEndian.PutUint16(bytes[1:], omci.AttributeExecutionMask) |
| 325 | } else { |
| 326 | binary.BigEndian.PutUint16(bytes[1:], 0) |
| 327 | } |
| 328 | return nil |
| 329 | } |
| 330 | |
| 331 | ///////////////////////////////////////////////////////////////////////////// |
| 332 | // DeleteRequest |
| 333 | type DeleteRequest struct { |
| 334 | MeBasePacket |
| 335 | } |
| 336 | |
| 337 | func (omci *DeleteRequest) String() string { |
| 338 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 339 | } |
| 340 | |
| 341 | // DecodeFromBytes decodes the given bytes of a Delete Request into this layer |
| 342 | func (omci *DeleteRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 343 | // Common ClassID/EntityID decode in msgBase |
| 344 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 345 | if err != nil { |
| 346 | return err |
| 347 | } |
| 348 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 349 | me.ParamData{EntityID: omci.EntityInstance}) |
| 350 | if omciErr.StatusCode() != me.Success { |
| 351 | return omciErr.GetError() |
| 352 | } |
| 353 | // ME needs to support Delete |
| 354 | if !me.SupportsMsgType(entity, me.Delete) { |
| 355 | return me.NewProcessingError("managed entity does not support the Delete Message-Type") |
| 356 | } |
| 357 | return nil |
| 358 | } |
| 359 | |
| 360 | func decodeDeleteRequest(data []byte, p gopacket.PacketBuilder) error { |
| 361 | omci := &DeleteRequest{} |
| 362 | omci.MsgLayerType = LayerTypeDeleteRequest |
| 363 | return decodingLayerDecoder(omci, data, p) |
| 364 | } |
| 365 | |
| 366 | // SerializeTo provides serialization of an Delete Request message |
| 367 | func (omci *DeleteRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 368 | // Basic (common) OMCI Header is 8 octets, 10 |
| 369 | err := omci.MeBasePacket.SerializeTo(b) |
| 370 | if err != nil { |
| 371 | return err |
| 372 | } |
| 373 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 374 | me.ParamData{EntityID: omci.EntityInstance}) |
| 375 | if omciErr.StatusCode() != me.Success { |
| 376 | return omciErr.GetError() |
| 377 | } |
| 378 | // ME needs to support Delete |
| 379 | if !me.SupportsMsgType(entity, me.Delete) { |
| 380 | return me.NewProcessingError("managed entity does not support the Delete Message-Type") |
| 381 | } |
| 382 | return nil |
| 383 | } |
| 384 | |
| 385 | ///////////////////////////////////////////////////////////////////////////// |
| 386 | // DeleteResponse |
| 387 | type DeleteResponse struct { |
| 388 | MeBasePacket |
| 389 | Result me.Results |
| 390 | } |
| 391 | |
| 392 | func (omci *DeleteResponse) String() string { |
| 393 | return fmt.Sprintf("%v, Result: %d (%v)", |
| 394 | omci.MeBasePacket.String(), omci.Result, omci.Result) |
| 395 | } |
| 396 | |
| 397 | // DecodeFromBytes decodes the given bytes of a Delete Response into this layer |
| 398 | func (omci *DeleteResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 399 | // Common ClassID/EntityID decode in msgBase |
| 400 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 401 | if err != nil { |
| 402 | return err |
| 403 | } |
| 404 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 405 | me.ParamData{EntityID: omci.EntityInstance}) |
| 406 | if omciErr.StatusCode() != me.Success { |
| 407 | return omciErr.GetError() |
| 408 | } |
| 409 | // ME needs to support Delete |
| 410 | if !me.SupportsMsgType(entity, me.Delete) { |
| 411 | return me.NewProcessingError("managed entity does not support the Delete Message-Type") |
| 412 | } |
| 413 | omci.Result = me.Results(data[4]) |
| 414 | return nil |
| 415 | } |
| 416 | |
| 417 | func decodeDeleteResponse(data []byte, p gopacket.PacketBuilder) error { |
| 418 | omci := &DeleteResponse{} |
| 419 | omci.MsgLayerType = LayerTypeDeleteResponse |
| 420 | return decodingLayerDecoder(omci, data, p) |
| 421 | } |
| 422 | |
| 423 | // SerializeTo provides serialization of an Delete Response message |
| 424 | func (omci *DeleteResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 425 | // Basic (common) OMCI Header is 8 octets, 10 |
| 426 | err := omci.MeBasePacket.SerializeTo(b) |
| 427 | if err != nil { |
| 428 | return err |
| 429 | } |
| 430 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 431 | me.ParamData{EntityID: omci.EntityInstance}) |
| 432 | if omciErr.StatusCode() != me.Success { |
| 433 | return omciErr.GetError() |
| 434 | } |
| 435 | // ME needs to support Delete |
| 436 | if !me.SupportsMsgType(entity, me.Delete) { |
| 437 | return me.NewProcessingError("managed entity does not support the Delete Message-Type") |
| 438 | } |
| 439 | bytes, err := b.AppendBytes(1) |
| 440 | if err != nil { |
| 441 | return err |
| 442 | } |
| 443 | bytes[0] = byte(omci.Result) |
| 444 | return nil |
| 445 | } |
| 446 | |
| 447 | ///////////////////////////////////////////////////////////////////////////// |
| 448 | // SetRequest |
| 449 | type SetRequest struct { |
| 450 | MeBasePacket |
| 451 | AttributeMask uint16 |
| 452 | Attributes me.AttributeValueMap |
| 453 | } |
| 454 | |
| 455 | func (omci *SetRequest) String() string { |
| 456 | return fmt.Sprintf("%v, Mask: %#x, attributes: %v", |
| 457 | omci.MeBasePacket.String(), omci.AttributeMask, omci.Attributes) |
| 458 | } |
| 459 | |
| 460 | // DecodeFromBytes decodes the given bytes of a Set Request into this layer |
| 461 | func (omci *SetRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 462 | // Common ClassID/EntityID decode in msgBase |
| 463 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 464 | if err != nil { |
| 465 | return err |
| 466 | } |
| 467 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 468 | me.ParamData{EntityID: omci.EntityInstance}) |
| 469 | if omciErr.StatusCode() != me.Success { |
| 470 | return omciErr.GetError() |
| 471 | } |
| 472 | // ME needs to support Set |
| 473 | if !me.SupportsMsgType(meDefinition, me.Set) { |
| 474 | return me.NewProcessingError("managed entity does not support Set Message-Type") |
| 475 | } |
| 476 | omci.AttributeMask = binary.BigEndian.Uint16(data[4:6]) |
| 477 | |
| 478 | // Attribute decode |
| 479 | omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[6:], p, byte(SetRequestType)) |
| 480 | if err != nil { |
| 481 | return err |
| 482 | } |
| 483 | // Validate all attributes support write |
| 484 | for attrName := range omci.Attributes { |
| 485 | attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName) |
| 486 | if err != nil { |
| 487 | return err |
| 488 | } |
| 489 | if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Write) { |
| 490 | msg := fmt.Sprintf("attribute '%v' does not support write access", attrName) |
| 491 | return me.NewProcessingError(msg) |
| 492 | } |
| 493 | } |
| 494 | if eidDef, eidDefOK := meDefinition.GetAttributeDefinitions()[0]; eidDefOK { |
| 495 | omci.Attributes[eidDef.GetName()] = omci.EntityInstance |
| 496 | return nil |
| 497 | } |
| 498 | panic("All Managed Entities have an EntityID attribute") |
| 499 | } |
| 500 | |
| 501 | func decodeSetRequest(data []byte, p gopacket.PacketBuilder) error { |
| 502 | omci := &SetRequest{} |
| 503 | omci.MsgLayerType = LayerTypeSetRequest |
| 504 | return decodingLayerDecoder(omci, data, p) |
| 505 | } |
| 506 | |
| 507 | // SerializeTo provides serialization of an Set Request message |
| 508 | func (omci *SetRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 509 | // Basic (common) OMCI Header is 8 octets, 10 |
| 510 | err := omci.MeBasePacket.SerializeTo(b) |
| 511 | if err != nil { |
| 512 | return err |
| 513 | } |
| 514 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 515 | me.ParamData{EntityID: omci.EntityInstance}) |
| 516 | if omciErr.StatusCode() != me.Success { |
| 517 | return omciErr.GetError() |
| 518 | } |
| 519 | // ME needs to support Set |
| 520 | if !me.SupportsMsgType(meDefinition, me.Set) { |
| 521 | return me.NewProcessingError("managed entity does not support Set Message-Type") |
| 522 | } |
| 523 | // Validate all attributes support write |
| 524 | for attrName := range omci.Attributes { |
| 525 | attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName) |
| 526 | if err != nil { |
| 527 | return err |
| 528 | } |
| 529 | // Do not test for write of Entity ID in the attribute list |
| 530 | if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Write) { |
| 531 | // TODO: Check ITU spec to see if this should be listed as a failed |
| 532 | // attribute and not a processing error. |
| 533 | msg := fmt.Sprintf("attribute '%v' does not support write access", attrName) |
| 534 | return me.NewProcessingError(msg) |
| 535 | } |
| 536 | } |
| 537 | bytes, err := b.AppendBytes(2) |
| 538 | if err != nil { |
| 539 | return err |
| 540 | } |
| 541 | binary.BigEndian.PutUint16(bytes, omci.AttributeMask) |
| 542 | |
| 543 | // Attribute serialization |
| 544 | // TODO: Only Baseline supported at this time |
| 545 | bytesAvailable := MaxBaselineLength - 10 - 8 |
| 546 | |
| 547 | err, _ = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b, |
| 548 | byte(SetRequestType), bytesAvailable, false) |
| 549 | return err |
| 550 | } |
| 551 | |
| 552 | ///////////////////////////////////////////////////////////////////////////// |
| 553 | // SetResponse |
| 554 | type SetResponse struct { |
| 555 | MeBasePacket |
| 556 | Result me.Results |
| 557 | UnsupportedAttributeMask uint16 |
| 558 | FailedAttributeMask uint16 |
| 559 | } |
| 560 | |
| 561 | func (omci *SetResponse) String() string { |
| 562 | return fmt.Sprintf("%v, Result: %d (%v), Unsupported Mask: %#x, Failed Mask: %#x", |
| 563 | omci.MeBasePacket.String(), omci.Result, omci.Result, omci.UnsupportedAttributeMask, |
| 564 | omci.FailedAttributeMask) |
| 565 | } |
| 566 | |
| 567 | // DecodeFromBytes decodes the given bytes of a Set Response into this layer |
| 568 | func (omci *SetResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 569 | // Common ClassID/EntityID decode in msgBase |
| 570 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 571 | if err != nil { |
| 572 | return err |
| 573 | } |
| 574 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 575 | me.ParamData{EntityID: omci.EntityInstance}) |
| 576 | if omciErr.StatusCode() != me.Success { |
| 577 | return omciErr.GetError() |
| 578 | } |
| 579 | // ME needs to support Set |
| 580 | if !me.SupportsMsgType(entity, me.Set) { |
| 581 | return me.NewProcessingError("managed entity does not support the Delete Message-Type") |
| 582 | } |
| 583 | omci.Result = me.Results(data[4]) |
| 584 | |
| 585 | if omci.Result == me.AttributeFailure { |
| 586 | omci.UnsupportedAttributeMask = binary.BigEndian.Uint16(data[5:7]) |
| 587 | omci.FailedAttributeMask = binary.BigEndian.Uint16(data[7:9]) |
| 588 | } |
| 589 | return nil |
| 590 | } |
| 591 | |
| 592 | func decodeSetResponse(data []byte, p gopacket.PacketBuilder) error { |
| 593 | omci := &SetResponse{} |
| 594 | omci.MsgLayerType = LayerTypeSetResponse |
| 595 | return decodingLayerDecoder(omci, data, p) |
| 596 | } |
| 597 | |
| 598 | // SerializeTo provides serialization of an Set Response message |
| 599 | func (omci *SetResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 600 | // Basic (common) OMCI Header is 8 octets, 10 |
| 601 | err := omci.MeBasePacket.SerializeTo(b) |
| 602 | if err != nil { |
| 603 | return err |
| 604 | } |
| 605 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 606 | me.ParamData{EntityID: omci.EntityInstance}) |
| 607 | if omciErr.StatusCode() != me.Success { |
| 608 | return omciErr.GetError() |
| 609 | } |
| 610 | // ME needs to support Set |
| 611 | if !me.SupportsMsgType(entity, me.Set) { |
| 612 | return me.NewProcessingError("managed entity does not support the Set Message-Type") |
| 613 | } |
| 614 | bytes, err := b.AppendBytes(5) |
| 615 | if err != nil { |
| 616 | return err |
| 617 | } |
| 618 | bytes[0] = byte(omci.Result) |
| 619 | binary.BigEndian.PutUint16(bytes[1:3], omci.UnsupportedAttributeMask) |
| 620 | binary.BigEndian.PutUint16(bytes[3:5], omci.FailedAttributeMask) |
| 621 | return nil |
| 622 | } |
| 623 | |
| 624 | ///////////////////////////////////////////////////////////////////////////// |
| 625 | // GetRequest |
| 626 | type GetRequest struct { |
| 627 | MeBasePacket |
| 628 | AttributeMask uint16 |
| 629 | } |
| 630 | |
| 631 | func (omci *GetRequest) String() string { |
| 632 | return fmt.Sprintf("%v, Mask: %#x", |
| 633 | omci.MeBasePacket.String(), omci.AttributeMask) |
| 634 | } |
| 635 | |
| 636 | // DecodeFromBytes decodes the given bytes of a Get Request into this layer |
| 637 | func (omci *GetRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 638 | // Common ClassID/EntityID decode in msgBase |
| 639 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 640 | if err != nil { |
| 641 | return err |
| 642 | } |
| 643 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 644 | me.ParamData{EntityID: omci.EntityInstance}) |
| 645 | if omciErr.StatusCode() != me.Success { |
| 646 | return omciErr.GetError() |
| 647 | } |
| 648 | // ME needs to support Get |
| 649 | if !me.SupportsMsgType(meDefinition, me.Get) { |
| 650 | return me.NewProcessingError("managed entity does not support Get Message-Type") |
| 651 | } |
| 652 | omci.AttributeMask = binary.BigEndian.Uint16(data[4:6]) |
| 653 | return nil |
| 654 | } |
| 655 | |
| 656 | func decodeGetRequest(data []byte, p gopacket.PacketBuilder) error { |
| 657 | omci := &GetRequest{} |
| 658 | omci.MsgLayerType = LayerTypeGetRequest |
| 659 | return decodingLayerDecoder(omci, data, p) |
| 660 | } |
| 661 | |
| 662 | // SerializeTo provides serialization of an Get Request message |
| 663 | func (omci *GetRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 664 | // Basic (common) OMCI Header is 8 octets, 10 |
| 665 | err := omci.MeBasePacket.SerializeTo(b) |
| 666 | if err != nil { |
| 667 | return err |
| 668 | } |
| 669 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 670 | me.ParamData{EntityID: omci.EntityInstance}) |
| 671 | if omciErr.StatusCode() != me.Success { |
| 672 | return omciErr.GetError() |
| 673 | } |
| 674 | // ME needs to support Set |
| 675 | if !me.SupportsMsgType(meDefinition, me.Get) { |
| 676 | return me.NewProcessingError("managed entity does not support Get Message-Type") |
| 677 | } |
| 678 | bytes, err := b.AppendBytes(2) |
| 679 | if err != nil { |
| 680 | return err |
| 681 | } |
| 682 | binary.BigEndian.PutUint16(bytes, omci.AttributeMask) |
| 683 | return nil |
| 684 | } |
| 685 | |
| 686 | ///////////////////////////////////////////////////////////////////////////// |
| 687 | // GetResponse |
| 688 | type GetResponse struct { |
| 689 | MeBasePacket |
| 690 | Result me.Results |
| 691 | AttributeMask uint16 |
| 692 | Attributes me.AttributeValueMap |
| 693 | UnsupportedAttributeMask uint16 |
| 694 | FailedAttributeMask uint16 |
| 695 | } |
| 696 | |
| 697 | func (omci *GetResponse) String() string { |
| 698 | return fmt.Sprintf("%v, Result: %d (%v), Mask: %#x, Unsupported: %#x, Failed: %#x, attributes: %v", |
| 699 | omci.MeBasePacket.String(), omci.Result, omci.Result, omci.AttributeMask, |
| 700 | omci.UnsupportedAttributeMask, omci.FailedAttributeMask, omci.Attributes) |
| 701 | } |
| 702 | |
| 703 | // DecodeFromBytes decodes the given bytes of a Get Response into this layer |
| 704 | func (omci *GetResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 705 | // Common ClassID/EntityID decode in msgBase |
| 706 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 707 | if err != nil { |
| 708 | return err |
| 709 | } |
| 710 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 711 | me.ParamData{EntityID: omci.EntityInstance}) |
| 712 | if omciErr.StatusCode() != me.Success { |
| 713 | return omciErr.GetError() |
| 714 | } |
| 715 | // ME needs to support Get |
| 716 | if !me.SupportsMsgType(meDefinition, me.Get) { |
| 717 | return me.NewProcessingError("managed entity does not support Get Message-Type") |
| 718 | } |
| 719 | omci.Result = me.Results(data[4]) |
| 720 | omci.AttributeMask = binary.BigEndian.Uint16(data[5:7]) |
| 721 | |
| 722 | // Attribute decode. Note that the ITU-T G.988 specification states that the |
| 723 | // Unsupported and Failed attribute masks are always present |
| 724 | // but only valid if the status code== 9. However some XGS |
| 725 | // ONUs (T&W and Alpha, perhaps more) will use these last 4 |
| 726 | // octets for data if the status code == 0. So accommodate |
| 727 | // this behaviour in favor of greater interoperability. |
| 728 | lastOctet := 36 |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 729 | |
| 730 | switch omci.Result { |
| 731 | case me.ProcessingError, me.NotSupported, me.UnknownEntity, me.UnknownInstance, me.DeviceBusy: |
| 732 | return nil // Done (do not try and decode attributes) |
| 733 | |
| 734 | case me.AttributeFailure: |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 735 | lastOctet = 32 |
| 736 | } |
| 737 | omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[7:lastOctet], p, byte(GetResponseType)) |
| 738 | if err != nil { |
| 739 | return err |
| 740 | } |
| 741 | // If Attribute failed or Unknown, decode optional attribute mask |
| 742 | if omci.Result == me.AttributeFailure { |
| 743 | omci.UnsupportedAttributeMask = binary.BigEndian.Uint16(data[32:34]) |
| 744 | omci.FailedAttributeMask = binary.BigEndian.Uint16(data[34:36]) |
| 745 | } |
| 746 | // Validate all attributes support read |
| 747 | for attrName := range omci.Attributes { |
| 748 | attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName) |
| 749 | if err != nil { |
| 750 | return err |
| 751 | } |
| 752 | if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Read) { |
| 753 | msg := fmt.Sprintf("attribute '%v' does not support read access", attrName) |
| 754 | return me.NewProcessingError(msg) |
| 755 | } |
| 756 | } |
| 757 | if eidDef, eidDefOK := meDefinition.GetAttributeDefinitions()[0]; eidDefOK { |
| 758 | omci.Attributes[eidDef.GetName()] = omci.EntityInstance |
| 759 | return nil |
| 760 | } |
| 761 | panic("All Managed Entities have an EntityID attribute") |
| 762 | } |
| 763 | |
| 764 | func decodeGetResponse(data []byte, p gopacket.PacketBuilder) error { |
| 765 | omci := &GetResponse{} |
| 766 | omci.MsgLayerType = LayerTypeGetResponse |
| 767 | return decodingLayerDecoder(omci, data, p) |
| 768 | } |
| 769 | |
| 770 | // SerializeTo provides serialization of an Get Response message |
| 771 | func (omci *GetResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 772 | // Basic (common) OMCI Header is 8 octets, 10 |
| 773 | if err := omci.MeBasePacket.SerializeTo(b); err != nil { |
| 774 | return err |
| 775 | } |
| 776 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 777 | me.ParamData{EntityID: omci.EntityInstance}) |
| 778 | |
| 779 | if omciErr.StatusCode() != me.Success { |
| 780 | return omciErr.GetError() |
| 781 | } |
| 782 | // ME needs to support Get |
| 783 | if !me.SupportsMsgType(meDefinition, me.Get) { |
| 784 | return me.NewProcessingError("managed entity does not support the Get Message-Type") |
| 785 | } |
| 786 | bytes, err := b.AppendBytes(3) |
| 787 | if err != nil { |
| 788 | return err |
| 789 | } |
| 790 | bytes[0] = byte(omci.Result) |
| 791 | binary.BigEndian.PutUint16(bytes[1:3], omci.AttributeMask) |
| 792 | |
| 793 | // Validate all attributes support read |
| 794 | for attrName := range omci.Attributes { |
| 795 | attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName) |
| 796 | if err != nil { |
| 797 | return err |
| 798 | } |
| 799 | if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Read) { |
| 800 | msg := fmt.Sprintf("attribute '%v' does not support read access", attrName) |
| 801 | return me.NewProcessingError(msg) |
| 802 | } |
| 803 | } |
| 804 | // Attribute serialization |
| 805 | switch omci.Result { |
| 806 | default: |
| 807 | break |
| 808 | |
| 809 | case me.Success, me.AttributeFailure: |
| 810 | // TODO: Baseline only supported at this time) |
| 811 | available := MaxBaselineLength - 11 - 4 - 8 |
| 812 | |
| 813 | // Serialize to temporary buffer if we may need to reset values due to |
| 814 | // recoverable truncation errors |
| 815 | origBuffer := b |
| 816 | b := gopacket.NewSerializeBuffer() |
| 817 | |
| 818 | err, failedMask := meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b, byte(GetResponseType), |
| 819 | available, opts.FixLengths) |
| 820 | |
| 821 | if err == nil && failedMask != 0 && opts.FixLengths { |
| 822 | // Not all attributes would fit |
| 823 | omci.FailedAttributeMask |= failedMask |
| 824 | omci.AttributeMask &= ^failedMask |
| 825 | omci.Result = me.AttributeFailure |
| 826 | |
| 827 | // Adjust already recorded values |
| 828 | bytes[0] = byte(omci.Result) |
| 829 | binary.BigEndian.PutUint16(bytes[1:3], omci.AttributeMask) |
| 830 | } else if err != nil { |
| 831 | return err |
| 832 | } |
| 833 | // Copy over attributes to the original serialization buffer |
| 834 | newSpace, err := origBuffer.AppendBytes(len(b.Bytes())) |
| 835 | if err != nil { |
| 836 | return err |
| 837 | } |
| 838 | copy(newSpace, b.Bytes()) |
| 839 | b = origBuffer |
| 840 | |
| 841 | // Calculate space left. Max - msgType header - OMCI trailer - spacedUsedSoFar |
| 842 | bytesLeft := MaxBaselineLength - 4 - 8 - len(b.Bytes()) |
| 843 | |
| 844 | remainingBytes, err := b.AppendBytes(bytesLeft + 4) |
| 845 | if err != nil { |
| 846 | return me.NewMessageTruncatedError(err.Error()) |
| 847 | } |
| 848 | copy(remainingBytes, lotsOfZeros[:]) |
| 849 | |
| 850 | if omci.Result == me.AttributeFailure { |
| 851 | binary.BigEndian.PutUint16(remainingBytes[bytesLeft-4:bytesLeft-2], omci.UnsupportedAttributeMask) |
| 852 | binary.BigEndian.PutUint16(remainingBytes[bytesLeft-2:bytesLeft], omci.FailedAttributeMask) |
| 853 | } |
| 854 | } |
| 855 | return nil |
| 856 | } |
| 857 | |
| 858 | ///////////////////////////////////////////////////////////////////////////// |
| 859 | // GetAllAlarms |
| 860 | type GetAllAlarmsRequest struct { |
| 861 | MeBasePacket |
| 862 | AlarmRetrievalMode byte |
| 863 | } |
| 864 | |
| 865 | func (omci *GetAllAlarmsRequest) String() string { |
| 866 | return fmt.Sprintf("%v, Retrieval Mode: %v", |
| 867 | omci.MeBasePacket.String(), omci.AlarmRetrievalMode) |
| 868 | } |
| 869 | |
| 870 | // DecodeFromBytes decodes the given bytes of a Get All Alarms Request into this layer |
| 871 | func (omci *GetAllAlarmsRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 872 | // Common ClassID/EntityID decode in msgBase |
| 873 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 874 | if err != nil { |
| 875 | return err |
| 876 | } |
| 877 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 878 | me.ParamData{EntityID: omci.EntityInstance}) |
| 879 | if omciErr.StatusCode() != me.Success { |
| 880 | return omciErr.GetError() |
| 881 | } |
| 882 | // ME needs to support Get All Alarms |
| 883 | if !me.SupportsMsgType(meDefinition, me.GetAllAlarms) { |
| 884 | return me.NewProcessingError("managed entity does not support Get All Alarms Message-Type") |
| 885 | } |
| 886 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 887 | if omci.EntityClass != me.OnuDataClassID { |
| 888 | msg := fmt.Sprintf("invalid Entity Class for Get All Alarms request: %v", |
| 889 | omci.EntityClass) |
| 890 | return me.NewProcessingError(msg) |
| 891 | } |
| 892 | if omci.EntityInstance != 0 { |
| 893 | msg := fmt.Sprintf("invalid Entity Instance for Get All Alarms request: %v", |
| 894 | omci.EntityInstance) |
| 895 | return me.NewUnknownInstanceError(msg) |
| 896 | } |
| 897 | omci.AlarmRetrievalMode = data[4] |
| 898 | if omci.AlarmRetrievalMode > 1 { |
| 899 | msg := fmt.Sprintf("invalid Alarm Retrieval Mode for Get All Alarms request: %v, must be 0..1", |
| 900 | omci.AlarmRetrievalMode) |
| 901 | return errors.New(msg) |
| 902 | } |
| 903 | return nil |
| 904 | } |
| 905 | |
| 906 | func decodeGetAllAlarmsRequest(data []byte, p gopacket.PacketBuilder) error { |
| 907 | omci := &GetAllAlarmsRequest{} |
| 908 | omci.MsgLayerType = LayerTypeGetAllAlarmsRequest |
| 909 | return decodingLayerDecoder(omci, data, p) |
| 910 | } |
| 911 | |
| 912 | // SerializeTo provides serialization of an Get All Alarms Request message |
| 913 | func (omci *GetAllAlarmsRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 914 | // Basic (common) OMCI Header is 8 octets, 10 |
| 915 | err := omci.MeBasePacket.SerializeTo(b) |
| 916 | if err != nil { |
| 917 | return err |
| 918 | } |
| 919 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 920 | me.ParamData{EntityID: omci.EntityInstance}) |
| 921 | if omciErr.StatusCode() != me.Success { |
| 922 | return omciErr.GetError() |
| 923 | } |
| 924 | // ME needs to support Get All Alarms |
| 925 | if !me.SupportsMsgType(entity, me.GetAllAlarms) { |
| 926 | return me.NewProcessingError("managed entity does not support the Get All Alarms Message-Type") |
| 927 | } |
| 928 | bytes, err := b.AppendBytes(1) |
| 929 | if err != nil { |
| 930 | return err |
| 931 | } |
| 932 | bytes[0] = omci.AlarmRetrievalMode |
| 933 | return nil |
| 934 | } |
| 935 | |
| 936 | ///////////////////////////////////////////////////////////////////////////// |
| 937 | // GetAllAlarms |
| 938 | type GetAllAlarmsResponse struct { |
| 939 | MeBasePacket |
| 940 | NumberOfCommands uint16 |
| 941 | } |
| 942 | |
| 943 | func (omci *GetAllAlarmsResponse) String() string { |
| 944 | return fmt.Sprintf("%v, NumberOfCommands: %d", |
| 945 | omci.MeBasePacket.String(), omci.NumberOfCommands) |
| 946 | } |
| 947 | |
| 948 | // DecodeFromBytes decodes the given bytes of a Get All Alarms Response into this layer |
| 949 | func (omci *GetAllAlarmsResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 950 | // Common ClassID/EntityID decode in msgBase |
| 951 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 952 | if err != nil { |
| 953 | return err |
| 954 | } |
| 955 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 956 | me.ParamData{EntityID: omci.EntityInstance}) |
| 957 | if omciErr.StatusCode() != me.Success { |
| 958 | return omciErr.GetError() |
| 959 | } |
| 960 | // ME needs to support Get All Alarms |
| 961 | if !me.SupportsMsgType(meDefinition, me.GetAllAlarms) { |
| 962 | return me.NewProcessingError("managed entity does not support Get All Alarms Message-Type") |
| 963 | } |
| 964 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 965 | if omci.EntityClass != me.OnuDataClassID { |
| 966 | msg := fmt.Sprintf("invalid Entity Class for Get All Alarms response: %v", |
| 967 | omci.EntityClass) |
| 968 | return me.NewProcessingError(msg) |
| 969 | } |
| 970 | if omci.EntityInstance != 0 { |
| 971 | msg := fmt.Sprintf("invalid Entity Instance for Get All Alarms response: %v", |
| 972 | omci.EntityInstance) |
| 973 | return me.NewUnknownInstanceError(msg) |
| 974 | } |
| 975 | omci.NumberOfCommands = binary.BigEndian.Uint16(data[4:6]) |
| 976 | return nil |
| 977 | } |
| 978 | |
| 979 | func decodeGetAllAlarmsResponse(data []byte, p gopacket.PacketBuilder) error { |
| 980 | omci := &GetAllAlarmsResponse{} |
| 981 | omci.MsgLayerType = LayerTypeGetAllAlarmsResponse |
| 982 | return decodingLayerDecoder(omci, data, p) |
| 983 | } |
| 984 | |
| 985 | // SerializeTo provides serialization of an Get All Alarms Response message |
| 986 | func (omci *GetAllAlarmsResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 987 | // Basic (common) OMCI Header is 8 octets, 10 |
| 988 | err := omci.MeBasePacket.SerializeTo(b) |
| 989 | if err != nil { |
| 990 | return err |
| 991 | } |
| 992 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 993 | me.ParamData{EntityID: omci.EntityInstance}) |
| 994 | if omciErr.StatusCode() != me.Success { |
| 995 | return omciErr.GetError() |
| 996 | } |
| 997 | // ME needs to support Get All Alarms |
| 998 | if !me.SupportsMsgType(entity, me.GetAllAlarms) { |
| 999 | return me.NewProcessingError("managed entity does not support the Get All Alarms Message-Type") |
| 1000 | } |
| 1001 | bytes, err := b.AppendBytes(2) |
| 1002 | if err != nil { |
| 1003 | return err |
| 1004 | } |
| 1005 | binary.BigEndian.PutUint16(bytes[0:2], omci.NumberOfCommands) |
| 1006 | return nil |
| 1007 | } |
| 1008 | |
| 1009 | ///////////////////////////////////////////////////////////////////////////// |
| 1010 | // GetAllAlarms |
| 1011 | type GetAllAlarmsNextRequest struct { |
| 1012 | MeBasePacket |
| 1013 | CommandSequenceNumber uint16 |
| 1014 | } |
| 1015 | |
| 1016 | func (omci *GetAllAlarmsNextRequest) String() string { |
| 1017 | return fmt.Sprintf("%v, Sequence Number: %d", |
| 1018 | omci.MeBasePacket.String(), omci.CommandSequenceNumber) |
| 1019 | } |
| 1020 | |
| 1021 | // DecodeFromBytes decodes the given bytes of a Get All Alarms Next Request into this layer |
| 1022 | func (omci *GetAllAlarmsNextRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1023 | // Common ClassID/EntityID decode in msgBase |
| 1024 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1025 | if err != nil { |
| 1026 | return err |
| 1027 | } |
| 1028 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1029 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1030 | if omciErr.StatusCode() != me.Success { |
| 1031 | return omciErr.GetError() |
| 1032 | } |
| 1033 | // ME needs to support Get All Alarms |
| 1034 | if !me.SupportsMsgType(meDefinition, me.GetAllAlarmsNext) { |
| 1035 | return me.NewProcessingError("managed entity does not support Get All Alarms Next Message-Type") |
| 1036 | } |
| 1037 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 1038 | if omci.EntityClass != me.OnuDataClassID { |
| 1039 | msg := fmt.Sprintf("invalid Entity Class for Get All Alarms Next request: %v", |
| 1040 | omci.EntityClass) |
| 1041 | return me.NewProcessingError(msg) |
| 1042 | } |
| 1043 | if omci.EntityInstance != 0 { |
| 1044 | msg := fmt.Sprintf("invalid Entity Instance for Get All Alarms Next request: %v", |
| 1045 | omci.EntityInstance) |
| 1046 | return me.NewUnknownInstanceError(msg) |
| 1047 | } |
| 1048 | omci.CommandSequenceNumber = binary.BigEndian.Uint16(data[4:6]) |
| 1049 | return nil |
| 1050 | } |
| 1051 | |
| 1052 | func decodeGetAllAlarmsNextRequest(data []byte, p gopacket.PacketBuilder) error { |
| 1053 | omci := &GetAllAlarmsNextRequest{} |
| 1054 | omci.MsgLayerType = LayerTypeGetAllAlarmsNextRequest |
| 1055 | return decodingLayerDecoder(omci, data, p) |
| 1056 | } |
| 1057 | |
| 1058 | // SerializeTo provides serialization of an Get All Alarms Next Request message |
| 1059 | func (omci *GetAllAlarmsNextRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1060 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1061 | err := omci.MeBasePacket.SerializeTo(b) |
| 1062 | if err != nil { |
| 1063 | return err |
| 1064 | } |
| 1065 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1066 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1067 | if omciErr.StatusCode() != me.Success { |
| 1068 | return omciErr.GetError() |
| 1069 | } |
| 1070 | // ME needs to support Get All Alarms Next |
| 1071 | if !me.SupportsMsgType(entity, me.GetAllAlarmsNext) { |
| 1072 | return me.NewProcessingError("managed entity does not support the Get All Alarms Next Message-Type") |
| 1073 | } |
| 1074 | bytes, err := b.AppendBytes(2) |
| 1075 | if err != nil { |
| 1076 | return err |
| 1077 | } |
| 1078 | binary.BigEndian.PutUint16(bytes, omci.CommandSequenceNumber) |
| 1079 | return nil |
| 1080 | } |
| 1081 | |
| 1082 | ///////////////////////////////////////////////////////////////////////////// |
| 1083 | // GetAllAlarms |
| 1084 | type GetAllAlarmsNextResponse struct { |
| 1085 | MeBasePacket |
| 1086 | AlarmEntityClass me.ClassID |
| 1087 | AlarmEntityInstance uint16 |
| 1088 | AlarmBitMap [28]byte // 224 bits |
| 1089 | } |
| 1090 | |
| 1091 | func (omci *GetAllAlarmsNextResponse) String() string { |
| 1092 | return fmt.Sprintf("%v, CID: %v, EID: (%d/%#x), Bitmap: %v", |
| 1093 | omci.MeBasePacket.String(), omci.AlarmEntityClass, omci.AlarmEntityInstance, |
| 1094 | omci.AlarmEntityInstance, omci.AlarmBitMap) |
| 1095 | } |
| 1096 | |
| 1097 | // DecodeFromBytes decodes the given bytes of a Get All Alarms Next Response into this layer |
| 1098 | func (omci *GetAllAlarmsNextResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1099 | // Common ClassID/EntityID decode in msgBase |
| 1100 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1101 | if err != nil { |
| 1102 | return err |
| 1103 | } |
| 1104 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1105 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1106 | if omciErr.StatusCode() != me.Success { |
| 1107 | return omciErr.GetError() |
| 1108 | } |
| 1109 | // ME needs to support Get All Alarms Next |
| 1110 | if !me.SupportsMsgType(meDefinition, me.GetAllAlarmsNext) { |
| 1111 | return me.NewProcessingError("managed entity does not support Get All Alarms Next Message-Type") |
| 1112 | } |
| 1113 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 1114 | if omci.EntityClass != me.OnuDataClassID { |
| 1115 | msg := fmt.Sprintf("invalid Entity Class for Get All Alarms Next response: %v", |
| 1116 | omci.EntityClass) |
| 1117 | return me.NewProcessingError(msg) |
| 1118 | } |
| 1119 | if omci.EntityInstance != 0 { |
| 1120 | msg := fmt.Sprintf("invalid Entity Instance for Get All Alarms Next response: %v", |
| 1121 | omci.EntityInstance) |
| 1122 | return me.NewUnknownInstanceError(msg) |
| 1123 | } |
| 1124 | omci.AlarmEntityClass = me.ClassID(binary.BigEndian.Uint16(data[4:6])) |
| 1125 | omci.AlarmEntityInstance = binary.BigEndian.Uint16(data[6:8]) |
| 1126 | |
| 1127 | copy(omci.AlarmBitMap[:], data[8:36]) |
| 1128 | return nil |
| 1129 | } |
| 1130 | |
| 1131 | func decodeGetAllAlarmsNextResponse(data []byte, p gopacket.PacketBuilder) error { |
| 1132 | omci := &GetAllAlarmsNextResponse{} |
| 1133 | omci.MsgLayerType = LayerTypeGetAllAlarmsNextResponse |
| 1134 | return decodingLayerDecoder(omci, data, p) |
| 1135 | } |
| 1136 | |
| 1137 | // SerializeTo provides serialization of an Get All Alarms Next Response message |
| 1138 | func (omci *GetAllAlarmsNextResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1139 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1140 | err := omci.MeBasePacket.SerializeTo(b) |
| 1141 | if err != nil { |
| 1142 | return err |
| 1143 | } |
| 1144 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1145 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1146 | if omciErr.StatusCode() != me.Success { |
| 1147 | return omciErr.GetError() |
| 1148 | } |
| 1149 | // ME needs to support Get All Alarms Next |
| 1150 | if !me.SupportsMsgType(entity, me.GetAllAlarmsNext) { |
| 1151 | return me.NewProcessingError("managed entity does not support the Get All Alarms Next Message-Type") |
| 1152 | } |
| 1153 | bytes, err := b.AppendBytes(2 + 2 + 28) |
| 1154 | if err != nil { |
| 1155 | return err |
| 1156 | } |
| 1157 | binary.BigEndian.PutUint16(bytes[0:], uint16(omci.AlarmEntityClass)) |
| 1158 | binary.BigEndian.PutUint16(bytes[2:], omci.AlarmEntityInstance) |
| 1159 | copy(bytes[4:], omci.AlarmBitMap[:]) |
| 1160 | return nil |
| 1161 | } |
| 1162 | |
| 1163 | ///////////////////////////////////////////////////////////////////////////// |
| 1164 | // MibUploadRequest |
| 1165 | type MibUploadRequest struct { |
| 1166 | MeBasePacket |
| 1167 | } |
| 1168 | |
| 1169 | func (omci *MibUploadRequest) String() string { |
| 1170 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 1171 | } |
| 1172 | |
| 1173 | // DecodeFromBytes decodes the given bytes of a MIB Upload Request into this layer |
| 1174 | func (omci *MibUploadRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1175 | // Common ClassID/EntityID decode in msgBase |
| 1176 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1177 | if err != nil { |
| 1178 | return err |
| 1179 | } |
| 1180 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1181 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1182 | if omciErr.StatusCode() != me.Success { |
| 1183 | return omciErr.GetError() |
| 1184 | } |
| 1185 | // ME needs to support MIB Upload |
| 1186 | if !me.SupportsMsgType(meDefinition, me.MibUpload) { |
| 1187 | return me.NewProcessingError("managed entity does not support MIB Upload Message-Type") |
| 1188 | } |
| 1189 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 1190 | if omci.EntityClass != me.OnuDataClassID { |
| 1191 | msg := fmt.Sprintf("invalid Entity Class for MIB Upload request: %v", |
| 1192 | omci.EntityClass) |
| 1193 | return me.NewProcessingError(msg) |
| 1194 | } |
| 1195 | if omci.EntityInstance != 0 { |
| 1196 | msg := fmt.Sprintf("invalid Entity Instance for MIB Upload request: %v", |
| 1197 | omci.EntityInstance) |
| 1198 | return me.NewUnknownInstanceError(msg) |
| 1199 | } |
| 1200 | return nil |
| 1201 | } |
| 1202 | |
| 1203 | func decodeMibUploadRequest(data []byte, p gopacket.PacketBuilder) error { |
| 1204 | omci := &MibUploadRequest{} |
| 1205 | omci.MsgLayerType = LayerTypeMibUploadRequest |
| 1206 | return decodingLayerDecoder(omci, data, p) |
| 1207 | } |
| 1208 | |
| 1209 | // SerializeTo provides serialization of an MIB Upload Request message |
| 1210 | func (omci *MibUploadRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1211 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1212 | err := omci.MeBasePacket.SerializeTo(b) |
| 1213 | if err != nil { |
| 1214 | return err |
| 1215 | } |
| 1216 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1217 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1218 | if omciErr.StatusCode() != me.Success { |
| 1219 | return omciErr.GetError() |
| 1220 | } |
| 1221 | // ME needs to support Get |
| 1222 | if !me.SupportsMsgType(meDefinition, me.MibUpload) { |
| 1223 | return me.NewProcessingError("managed entity does not support the MIB Upload Message-Type") |
| 1224 | } |
| 1225 | return nil |
| 1226 | } |
| 1227 | |
| 1228 | ///////////////////////////////////////////////////////////////////////////// |
| 1229 | // MibUploadResponse |
| 1230 | type MibUploadResponse struct { |
| 1231 | MeBasePacket |
| 1232 | NumberOfCommands uint16 |
| 1233 | } |
| 1234 | |
| 1235 | func (omci *MibUploadResponse) String() string { |
| 1236 | return fmt.Sprintf("%v, NumberOfCommands: %#v", |
| 1237 | omci.MeBasePacket.String(), omci.NumberOfCommands) |
| 1238 | } |
| 1239 | |
| 1240 | // DecodeFromBytes decodes the given bytes of a MIB Upload Response into this layer |
| 1241 | func (omci *MibUploadResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1242 | // Common ClassID/EntityID decode in msgBase |
| 1243 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1244 | if err != nil { |
| 1245 | return err |
| 1246 | } |
| 1247 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1248 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1249 | if omciErr.StatusCode() != me.Success { |
| 1250 | return omciErr.GetError() |
| 1251 | } |
| 1252 | // ME needs to support MIB Upload |
| 1253 | if !me.SupportsMsgType(meDefinition, me.MibUpload) { |
| 1254 | return me.NewProcessingError("managed entity does not support MIB Upload Message-Type") |
| 1255 | } |
| 1256 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 1257 | if omci.EntityClass != me.OnuDataClassID { |
| 1258 | msg := fmt.Sprintf("invalid Entity Class for MIB Upload response: %v", |
| 1259 | omci.EntityClass) |
| 1260 | return me.NewProcessingError(msg) |
| 1261 | } |
| 1262 | if omci.EntityInstance != 0 { |
| 1263 | msg := fmt.Sprintf("invalid Entity Instance for MIB Upload response: %v", |
| 1264 | omci.EntityInstance) |
| 1265 | return me.NewUnknownInstanceError(msg) |
| 1266 | } |
| 1267 | omci.NumberOfCommands = binary.BigEndian.Uint16(data[4:6]) |
| 1268 | return nil |
| 1269 | } |
| 1270 | |
| 1271 | func decodeMibUploadResponse(data []byte, p gopacket.PacketBuilder) error { |
| 1272 | omci := &MibUploadResponse{} |
| 1273 | omci.MsgLayerType = LayerTypeMibUploadResponse |
| 1274 | return decodingLayerDecoder(omci, data, p) |
| 1275 | } |
| 1276 | |
| 1277 | // SerializeTo provides serialization of an MIB Upload Response message |
| 1278 | func (omci *MibUploadResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1279 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1280 | err := omci.MeBasePacket.SerializeTo(b) |
| 1281 | if err != nil { |
| 1282 | return err |
| 1283 | } |
| 1284 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1285 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1286 | if omciErr.StatusCode() != me.Success { |
| 1287 | return omciErr.GetError() |
| 1288 | } |
| 1289 | // ME needs to support MIB Upload |
| 1290 | if !me.SupportsMsgType(entity, me.MibUpload) { |
| 1291 | return me.NewProcessingError("managed entity does not support the MIB Upload Message-Type") |
| 1292 | } |
| 1293 | bytes, err := b.AppendBytes(2) |
| 1294 | if err != nil { |
| 1295 | return err |
| 1296 | } |
| 1297 | binary.BigEndian.PutUint16(bytes[0:2], omci.NumberOfCommands) |
| 1298 | return nil |
| 1299 | } |
| 1300 | |
| 1301 | ///////////////////////////////////////////////////////////////////////////// |
| 1302 | // |
| 1303 | type MibUploadNextRequest struct { |
| 1304 | MeBasePacket |
| 1305 | CommandSequenceNumber uint16 |
| 1306 | } |
| 1307 | |
| 1308 | func (omci *MibUploadNextRequest) String() string { |
| 1309 | return fmt.Sprintf("%v, SequenceNumberCountOrSize: %v", |
| 1310 | omci.MeBasePacket.String(), omci.CommandSequenceNumber) |
| 1311 | } |
| 1312 | |
| 1313 | // DecodeFromBytes decodes the given bytes of a MIB Upload Next Request into this layer |
| 1314 | func (omci *MibUploadNextRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1315 | // Common ClassID/EntityID decode in msgBase |
| 1316 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1317 | if err != nil { |
| 1318 | return err |
| 1319 | } |
| 1320 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1321 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1322 | if omciErr.StatusCode() != me.Success { |
| 1323 | return omciErr.GetError() |
| 1324 | } |
| 1325 | // ME needs to support Get All Alarms |
| 1326 | if !me.SupportsMsgType(meDefinition, me.MibUploadNext) { |
| 1327 | return me.NewProcessingError("managed entity does not support MIB Upload Next Message-Type") |
| 1328 | } |
| 1329 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 1330 | if omci.EntityClass != me.OnuDataClassID { |
| 1331 | msg := fmt.Sprintf("invalid Entity Class for MIB Upload Next request: %v", |
| 1332 | omci.EntityClass) |
| 1333 | return me.NewProcessingError(msg) |
| 1334 | } |
| 1335 | if omci.EntityInstance != 0 { |
| 1336 | msg := fmt.Sprintf("invalid Entity Instance for MIB Upload Next request: %v", |
| 1337 | omci.EntityInstance) |
| 1338 | return me.NewUnknownInstanceError(msg) |
| 1339 | } |
| 1340 | omci.CommandSequenceNumber = binary.BigEndian.Uint16(data[4:6]) |
| 1341 | return nil |
| 1342 | } |
| 1343 | |
| 1344 | func decodeMibUploadNextRequest(data []byte, p gopacket.PacketBuilder) error { |
| 1345 | omci := &MibUploadNextRequest{} |
| 1346 | omci.MsgLayerType = LayerTypeMibUploadNextRequest |
| 1347 | return decodingLayerDecoder(omci, data, p) |
| 1348 | } |
| 1349 | |
| 1350 | // SerializeTo provides serialization of an MIB Upload Next Request message |
| 1351 | func (omci *MibUploadNextRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1352 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1353 | err := omci.MeBasePacket.SerializeTo(b) |
| 1354 | if err != nil { |
| 1355 | return err |
| 1356 | } |
| 1357 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1358 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1359 | if omciErr.StatusCode() != me.Success { |
| 1360 | return omciErr.GetError() |
| 1361 | } |
| 1362 | // ME needs to support MIB upload |
| 1363 | if !me.SupportsMsgType(entity, me.MibUploadNext) { |
| 1364 | return me.NewProcessingError("managed entity does not support the MIB Upload Next Message-Type") |
| 1365 | } |
| 1366 | bytes, err := b.AppendBytes(2) |
| 1367 | if err != nil { |
| 1368 | return err |
| 1369 | } |
| 1370 | binary.BigEndian.PutUint16(bytes[0:2], omci.CommandSequenceNumber) |
| 1371 | return nil |
| 1372 | } |
| 1373 | |
| 1374 | ///////////////////////////////////////////////////////////////////////////// |
| 1375 | // |
| 1376 | type MibUploadNextResponse struct { |
| 1377 | MeBasePacket |
| 1378 | ReportedME me.ManagedEntity |
| 1379 | } |
| 1380 | |
| 1381 | func (omci *MibUploadNextResponse) String() string { |
| 1382 | return fmt.Sprintf("%v, ReportedME: [%v]", |
| 1383 | omci.MeBasePacket.String(), omci.ReportedME.String()) |
| 1384 | } |
| 1385 | |
| 1386 | // DecodeFromBytes decodes the given bytes of a MIB Upload Next Response into this layer |
| 1387 | func (omci *MibUploadNextResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1388 | // Common ClassID/EntityID decode in msgBase |
| 1389 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1390 | if err != nil { |
| 1391 | return err |
| 1392 | } |
| 1393 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1394 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1395 | if omciErr.StatusCode() != me.Success { |
| 1396 | return omciErr.GetError() |
| 1397 | } |
| 1398 | // ME needs to support MibUploadNext |
| 1399 | if !me.SupportsMsgType(meDefinition, me.MibUploadNext) { |
| 1400 | return me.NewProcessingError("managed entity does not support MIB Upload Next Message-Type") |
| 1401 | } |
| 1402 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 1403 | if omci.EntityClass != me.OnuDataClassID { |
| 1404 | msg := fmt.Sprintf("invalid Entity Class for MIB Upload Next response: %v", |
| 1405 | omci.EntityClass) |
| 1406 | return me.NewProcessingError(msg) |
| 1407 | } |
| 1408 | if omci.EntityInstance != 0 { |
| 1409 | msg := fmt.Sprintf("invalid Entity Instance for MIB Upload Next response: %v", |
| 1410 | omci.EntityInstance) |
| 1411 | return me.NewUnknownInstanceError(msg) |
| 1412 | } |
| 1413 | // Decode reported ME. If an out-of-range sequence number was sent, this will |
| 1414 | // contain an ME with class ID and entity ID of zero and you should get an |
| 1415 | // error of "managed entity definition not found" returned. |
| 1416 | return omci.ReportedME.DecodeFromBytes(data[4:], p, byte(MibUploadNextResponseType)) |
| 1417 | } |
| 1418 | |
| 1419 | func decodeMibUploadNextResponse(data []byte, p gopacket.PacketBuilder) error { |
| 1420 | omci := &MibUploadNextResponse{} |
| 1421 | omci.MsgLayerType = LayerTypeMibUploadNextResponse |
| 1422 | return decodingLayerDecoder(omci, data, p) |
| 1423 | } |
| 1424 | |
| 1425 | // SerializeTo provides serialization of an MIB Upload Next Response message |
| 1426 | func (omci *MibUploadNextResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1427 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1428 | err := omci.MeBasePacket.SerializeTo(b) |
| 1429 | if err != nil { |
| 1430 | return err |
| 1431 | } |
| 1432 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1433 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1434 | if omciErr.StatusCode() != me.Success { |
| 1435 | return omciErr.GetError() |
| 1436 | } |
| 1437 | // ME needs to support MIB Upload |
| 1438 | if !me.SupportsMsgType(entity, me.MibUploadNext) { |
| 1439 | return me.NewProcessingError("managed entity does not support the MIB Upload Next Message-Type") |
| 1440 | } |
| 1441 | // TODO: Only Baseline supported at this time |
| 1442 | bytesAvailable := MaxBaselineLength - 8 - 8 |
| 1443 | |
| 1444 | return omci.ReportedME.SerializeTo(b, byte(MibUploadNextResponseType), bytesAvailable, opts) |
| 1445 | } |
| 1446 | |
| 1447 | ///////////////////////////////////////////////////////////////////////////// |
| 1448 | // MibResetRequest |
| 1449 | type MibResetRequest struct { |
| 1450 | MeBasePacket |
| 1451 | } |
| 1452 | |
| 1453 | func (omci *MibResetRequest) String() string { |
| 1454 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 1455 | } |
| 1456 | |
| 1457 | // DecodeFromBytes decodes the given bytes of a MIB Reset Request into this layer |
| 1458 | func (omci *MibResetRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1459 | // Common ClassID/EntityID decode in msgBase |
| 1460 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1461 | if err != nil { |
| 1462 | return err |
| 1463 | } |
| 1464 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1465 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1466 | if omciErr.StatusCode() != me.Success { |
| 1467 | return omciErr.GetError() |
| 1468 | } |
| 1469 | // ME needs to support MIB reset |
| 1470 | if !me.SupportsMsgType(meDefinition, me.MibReset) { |
| 1471 | return me.NewProcessingError("managed entity does not support MIB Reset Message-Type") |
| 1472 | } |
| 1473 | // Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 1474 | if omci.EntityClass != me.OnuDataClassID { |
| 1475 | msg := fmt.Sprintf("invalid Entity Class for MIB Reset request: %v", |
| 1476 | omci.EntityClass) |
| 1477 | return me.NewProcessingError(msg) |
| 1478 | } |
| 1479 | if omci.EntityInstance != 0 { |
| 1480 | msg := fmt.Sprintf("invalid Entity Instance for MIB Reset request: %v", |
| 1481 | omci.EntityInstance) |
| 1482 | return me.NewUnknownInstanceError(msg) |
| 1483 | } |
| 1484 | return nil |
| 1485 | } |
| 1486 | |
| 1487 | func decodeMibResetRequest(data []byte, p gopacket.PacketBuilder) error { |
| 1488 | omci := &MibResetRequest{} |
| 1489 | omci.MsgLayerType = LayerTypeMibResetRequest |
| 1490 | return decodingLayerDecoder(omci, data, p) |
| 1491 | } |
| 1492 | |
| 1493 | // SerializeTo provides serialization of an MIB Reset Request message |
| 1494 | func (omci *MibResetRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1495 | // Add class ID and entity ID |
| 1496 | return omci.MeBasePacket.SerializeTo(b) |
| 1497 | } |
| 1498 | |
| 1499 | ///////////////////////////////////////////////////////////////////////////// |
| 1500 | // MibResetResponse |
| 1501 | type MibResetResponse struct { |
| 1502 | MeBasePacket |
| 1503 | Result me.Results |
| 1504 | } |
| 1505 | |
| 1506 | func (omci *MibResetResponse) String() string { |
| 1507 | return fmt.Sprintf("%v, Result: %d (%v)", |
| 1508 | omci.MeBasePacket.String(), omci.Result, omci.Result) |
| 1509 | } |
| 1510 | |
| 1511 | // DecodeFromBytes decodes the given bytes of a MIB Reset Response into this layer |
| 1512 | func (omci *MibResetResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1513 | // Common ClassID/EntityID decode in msgBase |
| 1514 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1515 | if err != nil { |
| 1516 | return err |
| 1517 | } |
| 1518 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1519 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1520 | if omciErr.StatusCode() != me.Success { |
| 1521 | return omciErr.GetError() |
| 1522 | } |
| 1523 | // ME needs to support MIB reset |
| 1524 | if !me.SupportsMsgType(meDefinition, me.MibReset) { |
| 1525 | return me.NewProcessingError("managed entity does not support MIB Reset Message-Type") |
| 1526 | } |
| 1527 | // MIB Reset Response Entity Class always ONU DATA (2) and |
| 1528 | // Entity Instance of 0 |
| 1529 | if omci.EntityClass != me.OnuDataClassID { |
| 1530 | return me.NewProcessingError("invalid Entity Class for MIB Reset Response") |
| 1531 | } |
| 1532 | if omci.EntityInstance != 0 { |
| 1533 | return me.NewUnknownInstanceError("invalid Entity Instance for MIB Reset Response") |
| 1534 | } |
| 1535 | omci.Result = me.Results(data[4]) |
| 1536 | if omci.Result > me.DeviceBusy { |
| 1537 | msg := fmt.Sprintf("invalid results code: %v, must be 0..8", omci.Result) |
| 1538 | return errors.New(msg) |
| 1539 | } |
| 1540 | return nil |
| 1541 | } |
| 1542 | |
| 1543 | func decodeMibResetResponse(data []byte, p gopacket.PacketBuilder) error { |
| 1544 | omci := &MibResetResponse{} |
| 1545 | omci.MsgLayerType = LayerTypeMibResetResponse |
| 1546 | return decodingLayerDecoder(omci, data, p) |
| 1547 | } |
| 1548 | |
| 1549 | // SerializeTo provides serialization of an MIB Reset Response message |
| 1550 | func (omci *MibResetResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1551 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1552 | err := omci.MeBasePacket.SerializeTo(b) |
| 1553 | if err != nil { |
| 1554 | return err |
| 1555 | } |
| 1556 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1557 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1558 | if omciErr.StatusCode() != me.Success { |
| 1559 | return omciErr.GetError() |
| 1560 | } |
| 1561 | // ME needs to support Set |
| 1562 | if !me.SupportsMsgType(entity, me.MibReset) { |
| 1563 | return me.NewProcessingError("managed entity does not support the MIB Reset Message-Type") |
| 1564 | } |
| 1565 | bytes, err := b.AppendBytes(1) |
| 1566 | if err != nil { |
| 1567 | return err |
| 1568 | } |
| 1569 | bytes[0] = byte(omci.Result) |
| 1570 | return nil |
| 1571 | } |
| 1572 | |
| 1573 | ///////////////////////////////////////////////////////////////////////////// |
| 1574 | // AlarmNotificationMsg |
| 1575 | const AlarmBitmapSize = 224 |
| 1576 | |
| 1577 | type AlarmNotificationMsg struct { |
| 1578 | MeBasePacket |
| 1579 | AlarmBitmap [AlarmBitmapSize / 8]byte |
| 1580 | zeroPadding [3]byte |
| 1581 | AlarmSequenceNumber byte |
| 1582 | } |
| 1583 | |
| 1584 | func (omci *AlarmNotificationMsg) String() string { |
| 1585 | return fmt.Sprintf("%v, Sequence Number: %d, Alarm Bitmap: %v", |
| 1586 | omci.MeBasePacket.String(), omci.AlarmSequenceNumber, omci.AlarmBitmap) |
| 1587 | } |
| 1588 | |
| 1589 | func (omci *AlarmNotificationMsg) IsAlarmActive(alarmNumber uint8) (bool, error) { |
| 1590 | if alarmNumber >= AlarmBitmapSize { |
| 1591 | msg := fmt.Sprintf("invalid alarm number: %v, must be 0..224", alarmNumber) |
| 1592 | return false, errors.New(msg) |
| 1593 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1594 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1595 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1596 | if omciErr.StatusCode() != me.Success { |
| 1597 | return false, omciErr.GetError() |
| 1598 | } |
| 1599 | alarmMap := entity.GetAlarmMap() |
| 1600 | if alarmMap == nil { |
| 1601 | msg := "Managed Entity does not support Alarm notifications" |
| 1602 | return false, errors.New(msg) |
| 1603 | } |
| 1604 | if _, ok := alarmMap[alarmNumber]; !ok { |
| 1605 | msg := fmt.Sprintf("unsupported invalid alarm number: %v", alarmNumber) |
| 1606 | return false, errors.New(msg) |
| 1607 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1608 | octet := alarmNumber / 8 |
| 1609 | bit := 7 - (alarmNumber % 8) |
| 1610 | return omci.AlarmBitmap[octet]>>bit == 1, nil |
| 1611 | } |
| 1612 | |
| 1613 | func (omci *AlarmNotificationMsg) IsAlarmClear(alarmNumber uint8) (bool, error) { |
| 1614 | if alarmNumber >= AlarmBitmapSize { |
| 1615 | msg := fmt.Sprintf("invalid alarm number: %v, must be 0..224", alarmNumber) |
| 1616 | return false, errors.New(msg) |
| 1617 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1618 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1619 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1620 | if omciErr.StatusCode() != me.Success { |
| 1621 | return false, omciErr.GetError() |
| 1622 | } |
| 1623 | alarmMap := entity.GetAlarmMap() |
| 1624 | if alarmMap == nil { |
| 1625 | return false, errors.New("Managed Entity does not support Alarm notifications") |
| 1626 | } |
| 1627 | if _, ok := alarmMap[alarmNumber]; !ok { |
| 1628 | msg := fmt.Sprintf("unsupported invalid alarm number: %v", alarmNumber) |
| 1629 | return false, errors.New(msg) |
| 1630 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1631 | octet := alarmNumber / 8 |
| 1632 | bit := 7 - (alarmNumber % 8) |
| 1633 | return omci.AlarmBitmap[octet]>>bit == 0, nil |
| 1634 | } |
| 1635 | |
| 1636 | func (omci *AlarmNotificationMsg) ActivateAlarm(alarmNumber uint8) error { |
| 1637 | if alarmNumber >= AlarmBitmapSize { |
| 1638 | msg := fmt.Sprintf("invalid alarm number: %v, must be 0..224", alarmNumber) |
| 1639 | return errors.New(msg) |
| 1640 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1641 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1642 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1643 | if omciErr.StatusCode() != me.Success { |
| 1644 | return omciErr.GetError() |
| 1645 | } |
| 1646 | alarmMap := entity.GetAlarmMap() |
| 1647 | if alarmMap == nil { |
| 1648 | return errors.New("Managed Entity does not support Alarm notifications") |
| 1649 | } |
| 1650 | if _, ok := alarmMap[alarmNumber]; !ok { |
| 1651 | msg := fmt.Sprintf("unsupported invalid alarm number: %v", alarmNumber) |
| 1652 | return errors.New(msg) |
| 1653 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1654 | octet := alarmNumber / 8 |
| 1655 | bit := 7 - (alarmNumber % 8) |
| 1656 | omci.AlarmBitmap[octet] |= 1 << bit |
| 1657 | return nil |
| 1658 | } |
| 1659 | |
| 1660 | func (omci *AlarmNotificationMsg) ClearAlarm(alarmNumber uint8) error { |
| 1661 | if alarmNumber >= AlarmBitmapSize { |
| 1662 | msg := fmt.Sprintf("invalid alarm number: %v, must be 0..224", alarmNumber) |
| 1663 | return errors.New(msg) |
| 1664 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1665 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1666 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1667 | if omciErr.StatusCode() != me.Success { |
| 1668 | return omciErr.GetError() |
| 1669 | } |
| 1670 | alarmMap := entity.GetAlarmMap() |
| 1671 | if alarmMap == nil { |
| 1672 | return errors.New("Managed Entity does not support Alarm notifications") |
| 1673 | } |
| 1674 | if _, ok := alarmMap[alarmNumber]; !ok { |
| 1675 | msg := fmt.Sprintf("unsupported invalid alarm number: %v", alarmNumber) |
| 1676 | return errors.New(msg) |
| 1677 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1678 | octet := alarmNumber / 8 |
| 1679 | bit := 7 - (alarmNumber % 8) |
| 1680 | omci.AlarmBitmap[octet] &= ^(1 << bit) |
| 1681 | return nil |
| 1682 | } |
| 1683 | |
| 1684 | // DecodeFromBytes decodes the given bytes of an Alarm Notification into this layer |
| 1685 | func (omci *AlarmNotificationMsg) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1686 | // Common ClassID/EntityID decode in msgBase |
| 1687 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1688 | if err != nil { |
| 1689 | return err |
| 1690 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1691 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1692 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1693 | if omciErr.StatusCode() != me.Success { |
| 1694 | return omciErr.GetError() |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1695 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1696 | // Is this an unsupported or vendor specific ME. If so, it is not an error to decode |
| 1697 | // the alarms. We just cannot provide any alarm names. Handle decode here. |
| 1698 | classSupport := meDefinition.GetClassSupport() |
| 1699 | isUnsupported := classSupport == me.UnsupportedManagedEntity || |
| 1700 | classSupport == me.UnsupportedVendorSpecificManagedEntity |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1701 | |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1702 | // Look for a non-nil/not empty Alarm Map to determine if this ME supports alarms |
| 1703 | if alarmMap := meDefinition.GetAlarmMap(); isUnsupported || (alarmMap != nil && len(alarmMap) > 0) { |
| 1704 | for index, octet := range data[4 : (AlarmBitmapSize/8)-4] { |
| 1705 | omci.AlarmBitmap[index] = octet |
| 1706 | } |
| 1707 | padOffset := 4 + (AlarmBitmapSize / 8) |
| 1708 | omci.zeroPadding[0] = data[padOffset] |
| 1709 | omci.zeroPadding[1] = data[padOffset+1] |
| 1710 | omci.zeroPadding[2] = data[padOffset+2] |
| 1711 | |
| 1712 | omci.AlarmSequenceNumber = data[padOffset+3] |
| 1713 | return nil |
| 1714 | } |
| 1715 | return me.NewProcessingError("managed entity does not support alarm notifications") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | func decodeAlarmNotification(data []byte, p gopacket.PacketBuilder) error { |
| 1719 | omci := &AlarmNotificationMsg{} |
| 1720 | omci.MsgLayerType = LayerTypeAlarmNotification |
| 1721 | return decodingLayerDecoder(omci, data, p) |
| 1722 | } |
| 1723 | |
| 1724 | // SerializeTo provides serialization of an Alarm Notification message |
| 1725 | func (omci *AlarmNotificationMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1726 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1727 | err := omci.MeBasePacket.SerializeTo(b) |
| 1728 | if err != nil { |
| 1729 | return err |
| 1730 | } |
| 1731 | //var meDefinition me.IManagedEntityDefinition |
| 1732 | //meDefinition, err = me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1733 | // me.ParamData{EntityID: omci.EntityInstance}) |
| 1734 | //if err != nil { |
| 1735 | // return err |
| 1736 | //} |
| 1737 | // ME needs to support Alarms |
| 1738 | // TODO: Add attribute to ME to specify that alarm is allowed |
| 1739 | //if !me.SupportsMsgType(meDefinition, me.MibReset) { |
| 1740 | // return me.NewProcessingError("managed entity does not support MIB Reset Message-Type") |
| 1741 | //} |
| 1742 | bytes, err := b.AppendBytes((AlarmBitmapSize / 8) + 3 + 1) |
| 1743 | if err != nil { |
| 1744 | return err |
| 1745 | } |
| 1746 | for index, octet := range omci.AlarmBitmap { |
| 1747 | bytes[index] = octet |
| 1748 | } |
| 1749 | padOffset := AlarmBitmapSize / 8 |
| 1750 | bytes[padOffset] = 0 |
| 1751 | bytes[padOffset+1] = 0 |
| 1752 | bytes[padOffset+2] = 0 |
| 1753 | bytes[padOffset+3] = omci.AlarmSequenceNumber |
| 1754 | return nil |
| 1755 | } |
| 1756 | |
| 1757 | ///////////////////////////////////////////////////////////////////////////// |
| 1758 | // AttributeValueChangeMsg |
| 1759 | type AttributeValueChangeMsg struct { |
| 1760 | MeBasePacket |
| 1761 | AttributeMask uint16 |
| 1762 | Attributes me.AttributeValueMap |
| 1763 | } |
| 1764 | |
| 1765 | func (omci *AttributeValueChangeMsg) String() string { |
| 1766 | return fmt.Sprintf("%v, Mask: %#x, attributes: %v", |
| 1767 | omci.MeBasePacket.String(), omci.AttributeMask, omci.Attributes) |
| 1768 | } |
| 1769 | |
| 1770 | // DecodeFromBytes decodes the given bytes of an Attribute Value Change notification into this layer |
| 1771 | func (omci *AttributeValueChangeMsg) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1772 | // Common ClassID/EntityID decode in msgBase |
| 1773 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1774 | if err != nil { |
| 1775 | return err |
| 1776 | } |
| 1777 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1778 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1779 | if omciErr.StatusCode() != me.Success { |
| 1780 | return omciErr.GetError() |
| 1781 | } |
| 1782 | omci.AttributeMask = binary.BigEndian.Uint16(data[4:6]) |
| 1783 | // Attribute decode |
| 1784 | omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[6:40], p, byte(AttributeValueChangeType)) |
| 1785 | // TODO: Add support for attributes that can have an AVC associated with them and then add a check here |
| 1786 | // Validate all attributes support AVC |
| 1787 | //for attrName := range omci.attributes { |
| 1788 | // attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName) |
| 1789 | // if err != nil { |
| 1790 | // return err |
| 1791 | // } |
| 1792 | // if attr.Index != 0 && !me.SupportsAttributeAVC(attr) { |
| 1793 | // msg := fmt.Sprintf("attribute '%v' does not support AVC notifications", attrName) |
| 1794 | // return me.NewProcessingError(msg) |
| 1795 | // } |
| 1796 | //} |
| 1797 | return err |
| 1798 | } |
| 1799 | |
| 1800 | func decodeAttributeValueChange(data []byte, p gopacket.PacketBuilder) error { |
| 1801 | omci := &AttributeValueChangeMsg{} |
| 1802 | omci.MsgLayerType = LayerTypeAttributeValueChange |
| 1803 | return decodingLayerDecoder(omci, data, p) |
| 1804 | } |
| 1805 | |
| 1806 | // SerializeTo provides serialization of an Attribute Value Change Notification message |
| 1807 | func (omci *AttributeValueChangeMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1808 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1809 | err := omci.MeBasePacket.SerializeTo(b) |
| 1810 | if err != nil { |
| 1811 | return err |
| 1812 | } |
| 1813 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1814 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1815 | if omciErr.StatusCode() != me.Success { |
| 1816 | return omciErr.GetError() |
| 1817 | } |
| 1818 | // TODO: Add support for attributes that can have an AVC associated with them and then add a check here |
| 1819 | // Validate all attributes support AVC |
| 1820 | //for attrName := range omci.attributes { |
| 1821 | // attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName) |
| 1822 | // if err != nil { |
| 1823 | // return err |
| 1824 | // } |
| 1825 | // if attr.Index != 0 && !me.SupportsAttributeAVC(attr) { |
| 1826 | // msg := fmt.Sprintf("attribute '%v' does not support AVC notifications", attrName) |
| 1827 | // return me.NewProcessingError(msg) |
| 1828 | // } |
| 1829 | //} |
| 1830 | bytes, err := b.AppendBytes(2) |
| 1831 | if err != nil { |
| 1832 | return err |
| 1833 | } |
| 1834 | binary.BigEndian.PutUint16(bytes, omci.AttributeMask) |
| 1835 | |
| 1836 | // Attribute serialization |
| 1837 | // TODO: Only Baseline supported at this time |
| 1838 | bytesAvailable := MaxBaselineLength - 10 - 8 |
| 1839 | |
| 1840 | err, _ = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b, |
| 1841 | byte(AttributeValueChangeType), bytesAvailable, false) |
| 1842 | return err |
| 1843 | } |
| 1844 | |
| 1845 | ///////////////////////////////////////////////////////////////////////////// |
| 1846 | // TestRequest: TODO: Not yet implemented |
| 1847 | type TestRequest struct { |
| 1848 | MeBasePacket |
| 1849 | } |
| 1850 | |
| 1851 | func (omci *TestRequest) String() string { |
| 1852 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 1853 | } |
| 1854 | |
| 1855 | // DecodeFromBytes decodes the given bytes of a Test Request into this layer |
| 1856 | func (omci *TestRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1857 | // Common ClassID/EntityID decode in msgBase |
| 1858 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1859 | if err != nil { |
| 1860 | return err |
| 1861 | } |
| 1862 | return errors.New("need to implement") // TODO: Fix me) // return nil |
| 1863 | } |
| 1864 | |
| 1865 | func decodeTestRequest(data []byte, p gopacket.PacketBuilder) error { |
| 1866 | omci := &TestRequest{} |
| 1867 | omci.MsgLayerType = LayerTypeTestRequest |
| 1868 | return decodingLayerDecoder(omci, data, p) |
| 1869 | } |
| 1870 | |
| 1871 | // SerializeTo provides serialization of an Test Request message |
| 1872 | func (omci *TestRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1873 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1874 | err := omci.MeBasePacket.SerializeTo(b) |
| 1875 | if err != nil { |
| 1876 | return err |
| 1877 | } |
| 1878 | return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b) |
| 1879 | } |
| 1880 | |
| 1881 | ///////////////////////////////////////////////////////////////////////////// |
| 1882 | // TestResponse: TODO: Not yet implemented |
| 1883 | type TestResponse struct { |
| 1884 | MeBasePacket |
| 1885 | } |
| 1886 | |
| 1887 | func (omci *TestResponse) String() string { |
| 1888 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 1889 | } |
| 1890 | |
| 1891 | // DecodeFromBytes decodes the given bytes of a Test Response into this layer |
| 1892 | func (omci *TestResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1893 | // Common ClassID/EntityID decode in msgBase |
| 1894 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1895 | if err != nil { |
| 1896 | return err |
| 1897 | } |
| 1898 | return errors.New("need to implement") // TODO: Fix me) // return nil |
| 1899 | } |
| 1900 | |
| 1901 | func decodeTestResponse(data []byte, p gopacket.PacketBuilder) error { |
| 1902 | omci := &TestResponse{} |
| 1903 | omci.MsgLayerType = LayerTypeTestResponse |
| 1904 | return decodingLayerDecoder(omci, data, p) |
| 1905 | } |
| 1906 | |
| 1907 | // SerializeTo provides serialization of an Test Response message |
| 1908 | func (omci *TestResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1909 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1910 | err := omci.MeBasePacket.SerializeTo(b) |
| 1911 | if err != nil { |
| 1912 | return err |
| 1913 | } |
| 1914 | return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b) |
| 1915 | } |
| 1916 | |
| 1917 | ///////////////////////////////////////////////////////////////////////////// |
| 1918 | // |
| 1919 | type StartSoftwareDownloadRequest struct { |
| 1920 | MeBasePacket // Note: EntityInstance for software download is two specific values |
| 1921 | WindowSize byte // Window Size -1 |
| 1922 | ImageSize uint32 // Octets |
| 1923 | NumberOfCircuitPacks byte |
| 1924 | CircuitPacks []uint16 // MSB & LSB of software image instance |
| 1925 | } |
| 1926 | |
| 1927 | func (omci *StartSoftwareDownloadRequest) String() string { |
| 1928 | return fmt.Sprintf("%v, Window Size: %v, Image Size: %v, # Circuit Packs: %v", |
| 1929 | omci.MeBasePacket.String(), omci.WindowSize, omci.ImageSize, omci.NumberOfCircuitPacks) |
| 1930 | } |
| 1931 | |
| 1932 | // DecodeFromBytes decodes the given bytes of a Start Software Download Request into this layer |
| 1933 | func (omci *StartSoftwareDownloadRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 1934 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 1935 | if err != nil { |
| 1936 | return err |
| 1937 | } |
| 1938 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1939 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1940 | if omciErr.StatusCode() != me.Success { |
| 1941 | return omciErr.GetError() |
| 1942 | } |
| 1943 | // ME needs to support Start Software Download |
| 1944 | if !me.SupportsMsgType(meDefinition, me.StartSoftwareDownload) { |
| 1945 | return me.NewProcessingError("managed entity does not support Start Software Download Message-Type") |
| 1946 | } |
| 1947 | // Software Image Entity Class are always use the Software Image |
| 1948 | if omci.EntityClass != me.SoftwareImageClassID { |
| 1949 | return me.NewProcessingError("invalid Entity Class for Start Software Download request") |
| 1950 | } |
| 1951 | omci.WindowSize = data[4] |
| 1952 | omci.ImageSize = binary.BigEndian.Uint32(data[5:9]) |
| 1953 | omci.NumberOfCircuitPacks = data[9] |
| 1954 | if omci.NumberOfCircuitPacks < 1 || omci.NumberOfCircuitPacks > 9 { |
| 1955 | return me.NewProcessingError(fmt.Sprintf("invalid number of Circuit Packs: %v, must be 1..9", |
| 1956 | omci.NumberOfCircuitPacks)) |
| 1957 | } |
| 1958 | omci.CircuitPacks = make([]uint16, omci.NumberOfCircuitPacks) |
| 1959 | for index := 0; index < int(omci.NumberOfCircuitPacks); index++ { |
| 1960 | omci.CircuitPacks[index] = binary.BigEndian.Uint16(data[10+(index*2):]) |
| 1961 | } |
| 1962 | return nil |
| 1963 | } |
| 1964 | |
| 1965 | func decodeStartSoftwareDownloadRequest(data []byte, p gopacket.PacketBuilder) error { |
| 1966 | omci := &StartSoftwareDownloadRequest{} |
| 1967 | omci.MsgLayerType = LayerTypeStartSoftwareDownloadRequest |
| 1968 | return decodingLayerDecoder(omci, data, p) |
| 1969 | } |
| 1970 | |
| 1971 | // SerializeTo provides serialization of an Start Software Download Request message |
| 1972 | func (omci *StartSoftwareDownloadRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 1973 | // Basic (common) OMCI Header is 8 octets, 10 |
| 1974 | err := omci.MeBasePacket.SerializeTo(b) |
| 1975 | if err != nil { |
| 1976 | return err |
| 1977 | } |
| 1978 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 1979 | me.ParamData{EntityID: omci.EntityInstance}) |
| 1980 | if omciErr.StatusCode() != me.Success { |
| 1981 | return omciErr.GetError() |
| 1982 | } |
| 1983 | // ME needs to support Start Software Download |
| 1984 | if !me.SupportsMsgType(entity, me.StartSoftwareDownload) { |
| 1985 | return me.NewProcessingError("managed entity does not support the SStart Software Download Message-Type") |
| 1986 | } |
| 1987 | // Software Image Entity Class are always use the Software Image |
| 1988 | if omci.EntityClass != me.SoftwareImageClassID { |
| 1989 | return me.NewProcessingError("invalid Entity Class for Start Software Download request") |
| 1990 | } |
| 1991 | if omci.NumberOfCircuitPacks < 1 || omci.NumberOfCircuitPacks > 9 { |
| 1992 | return me.NewProcessingError(fmt.Sprintf("invalid number of Circuit Packs: %v, must be 1..9", |
| 1993 | omci.NumberOfCircuitPacks)) |
| 1994 | } |
| 1995 | bytes, err := b.AppendBytes(6 + (2 * int(omci.NumberOfCircuitPacks))) |
| 1996 | if err != nil { |
| 1997 | return err |
| 1998 | } |
| 1999 | bytes[0] = omci.WindowSize |
| 2000 | binary.BigEndian.PutUint32(bytes[1:], omci.ImageSize) |
| 2001 | bytes[5] = omci.NumberOfCircuitPacks |
| 2002 | for index := 0; index < int(omci.NumberOfCircuitPacks); index++ { |
| 2003 | binary.BigEndian.PutUint16(bytes[6+(index*2):], omci.CircuitPacks[index]) |
| 2004 | } |
| 2005 | return nil |
| 2006 | } |
| 2007 | |
| 2008 | ///////////////////////////////////////////////////////////////////////////// |
| 2009 | // |
| 2010 | type downloadResults struct { |
| 2011 | ManagedEntityID uint16 // ME ID of software image entity instance (slot number plus instance 0..1 or 2..254 vendor-specific) |
| 2012 | Result me.Results |
| 2013 | } |
| 2014 | |
| 2015 | func (dr *downloadResults) String() string { |
| 2016 | return fmt.Sprintf("ME: %v (%#x), Results: %d (%v)", dr.ManagedEntityID, dr.ManagedEntityID, |
| 2017 | dr.Result, dr.Result) |
| 2018 | } |
| 2019 | |
| 2020 | type StartSoftwareDownloadResponse struct { |
| 2021 | MeBasePacket // Note: EntityInstance for software download is two specific values |
| 2022 | Result me.Results |
| 2023 | WindowSize byte // Window Size -1 |
| 2024 | NumberOfInstances byte |
| 2025 | MeResults []downloadResults |
| 2026 | } |
| 2027 | |
| 2028 | func (omci *StartSoftwareDownloadResponse) String() string { |
| 2029 | return fmt.Sprintf("%v, Results: %v, Window Size: %v, # of Instances: %v, ME Results: %v", |
| 2030 | omci.MeBasePacket.String(), omci.Result, omci.WindowSize, omci.NumberOfInstances, omci.MeResults) |
| 2031 | } |
| 2032 | |
| 2033 | // DecodeFromBytes decodes the given bytes of a Start Software Download Response into this layer |
| 2034 | func (omci *StartSoftwareDownloadResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2035 | // Common ClassID/EntityID decode in msgBase |
| 2036 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2037 | if err != nil { |
| 2038 | return err |
| 2039 | } |
| 2040 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2041 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2042 | if omciErr.StatusCode() != me.Success { |
| 2043 | return omciErr.GetError() |
| 2044 | } |
| 2045 | // ME needs to support Start Software Download |
| 2046 | if !me.SupportsMsgType(meDefinition, me.StartSoftwareDownload) { |
| 2047 | return me.NewProcessingError("managed entity does not support Start Software Download Message-Type") |
| 2048 | } |
| 2049 | // Software Image Entity Class are always use the Software Image |
| 2050 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2051 | return me.NewProcessingError("invalid Entity Class for Start Software Download response") |
| 2052 | } |
| 2053 | omci.Result = me.Results(data[4]) |
| 2054 | if omci.Result > me.DeviceBusy { |
| 2055 | msg := fmt.Sprintf("invalid results for Start Software Download response: %v, must be 0..6", |
| 2056 | omci.Result) |
| 2057 | return errors.New(msg) |
| 2058 | } |
| 2059 | omci.WindowSize = data[5] |
| 2060 | omci.NumberOfInstances = data[6] |
| 2061 | |
| 2062 | if omci.NumberOfInstances > 9 { |
| 2063 | msg := fmt.Sprintf("invalid number of Circuit Packs: %v, must be 0..9", |
| 2064 | omci.NumberOfInstances) |
| 2065 | return errors.New(msg) |
| 2066 | } |
| 2067 | if omci.NumberOfInstances > 0 { |
| 2068 | omci.MeResults = make([]downloadResults, omci.NumberOfInstances) |
| 2069 | |
| 2070 | for index := 0; index < int(omci.NumberOfInstances); index++ { |
| 2071 | omci.MeResults[index].ManagedEntityID = binary.BigEndian.Uint16(data[7+(index*3):]) |
| 2072 | omci.MeResults[index].Result = me.Results(data[9+(index*3)]) |
| 2073 | if omci.MeResults[index].Result > me.DeviceBusy { |
| 2074 | msg := fmt.Sprintf("invalid results for Start Software Download instance %v response: %v, must be 0..6", |
| 2075 | index, omci.MeResults[index]) |
| 2076 | return errors.New(msg) |
| 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | return nil |
| 2081 | } |
| 2082 | |
| 2083 | func decodeStartSoftwareDownloadResponse(data []byte, p gopacket.PacketBuilder) error { |
| 2084 | omci := &StartSoftwareDownloadResponse{} |
| 2085 | omci.MsgLayerType = LayerTypeStartSoftwareDownloadResponse |
| 2086 | return decodingLayerDecoder(omci, data, p) |
| 2087 | } |
| 2088 | |
| 2089 | // SerializeTo provides serialization of an Start Software Download Response message |
| 2090 | func (omci *StartSoftwareDownloadResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2091 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2092 | err := omci.MeBasePacket.SerializeTo(b) |
| 2093 | if err != nil { |
| 2094 | return err |
| 2095 | } |
| 2096 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2097 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2098 | if omciErr.StatusCode() != me.Success { |
| 2099 | return omciErr.GetError() |
| 2100 | } |
| 2101 | // ME needs to support Start Software Download |
| 2102 | if !me.SupportsMsgType(meDefinition, me.StartSoftwareDownload) { |
| 2103 | return me.NewProcessingError("managed entity does not support Start Software Download Message-Type") |
| 2104 | } |
| 2105 | // Software Image Entity Class are always use the Software Image |
| 2106 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2107 | return me.NewProcessingError("invalid Entity Class for Start Software Download response") |
| 2108 | } |
| 2109 | bytes, err := b.AppendBytes(3 + (3 * int(omci.NumberOfInstances))) |
| 2110 | if err != nil { |
| 2111 | return err |
| 2112 | } |
| 2113 | if omci.Result > me.DeviceBusy { |
| 2114 | msg := fmt.Sprintf("invalid results for Start Software Download response: %v, must be 0..6", |
| 2115 | omci.Result) |
| 2116 | return errors.New(msg) |
| 2117 | } |
| 2118 | bytes[0] = byte(omci.Result) |
| 2119 | bytes[1] = omci.WindowSize |
| 2120 | bytes[2] = omci.NumberOfInstances |
| 2121 | |
| 2122 | if omci.NumberOfInstances > 9 { |
| 2123 | msg := fmt.Sprintf("invalid number of Circuit Packs: %v, must be 0..9", |
| 2124 | omci.NumberOfInstances) |
| 2125 | return errors.New(msg) |
| 2126 | } |
| 2127 | if omci.NumberOfInstances > 0 { |
| 2128 | for index := 0; index < int(omci.NumberOfInstances); index++ { |
| 2129 | binary.BigEndian.PutUint16(bytes[3+(3*index):], omci.MeResults[index].ManagedEntityID) |
| 2130 | |
| 2131 | if omci.MeResults[index].Result > me.DeviceBusy { |
| 2132 | msg := fmt.Sprintf("invalid results for Start Software Download instance %v response: %v, must be 0..6", |
| 2133 | index, omci.MeResults[index]) |
| 2134 | return errors.New(msg) |
| 2135 | } |
| 2136 | bytes[5+(3*index)] = byte(omci.MeResults[index].Result) |
| 2137 | } |
| 2138 | } |
| 2139 | return nil |
| 2140 | } |
| 2141 | |
| 2142 | ///////////////////////////////////////////////////////////////////////////// |
| 2143 | // |
| 2144 | type DownloadSectionRequest struct { |
| 2145 | MeBasePacket // Note: EntityInstance for software download is two specific values |
| 2146 | SectionNumber byte |
Girish Gowdra | 8a7b456 | 2021-02-23 16:27:42 -0800 | [diff] [blame] | 2147 | SectionData [31]byte // 0 padding if final transfer requires only a partial block |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | func (omci *DownloadSectionRequest) String() string { |
| 2151 | return fmt.Sprintf("%v, Section #: %v", |
| 2152 | omci.MeBasePacket.String(), omci.SectionNumber) |
| 2153 | } |
| 2154 | |
| 2155 | // DecodeFromBytes decodes the given bytes of a Download Section Request into this layer |
| 2156 | func (omci *DownloadSectionRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2157 | // Common ClassID/EntityID decode in msgBase |
| 2158 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2159 | if err != nil { |
| 2160 | return err |
| 2161 | } |
| 2162 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2163 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2164 | if omciErr.StatusCode() != me.Success { |
| 2165 | return omciErr.GetError() |
| 2166 | } |
| 2167 | // ME needs to support Download section |
| 2168 | if !me.SupportsMsgType(meDefinition, me.DownloadSection) { |
| 2169 | return me.NewProcessingError("managed entity does not support Download Section Message-Type") |
| 2170 | } |
| 2171 | // Software Image Entity Class are always use the Software Image |
| 2172 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2173 | return me.NewProcessingError("invalid Entity Class for Download Section request") |
| 2174 | } |
| 2175 | omci.SectionNumber = data[4] |
| 2176 | copy(omci.SectionData[0:], data[5:]) |
| 2177 | return nil |
| 2178 | } |
| 2179 | |
| 2180 | func decodeDownloadSectionRequest(data []byte, p gopacket.PacketBuilder) error { |
| 2181 | omci := &DownloadSectionRequest{} |
| 2182 | omci.MsgLayerType = LayerTypeDownloadSectionRequest |
| 2183 | return decodingLayerDecoder(omci, data, p) |
| 2184 | } |
| 2185 | |
| 2186 | // SerializeTo provides serialization of an Download Section Request message |
| 2187 | func (omci *DownloadSectionRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2188 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2189 | err := omci.MeBasePacket.SerializeTo(b) |
| 2190 | if err != nil { |
| 2191 | return err |
| 2192 | } |
| 2193 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2194 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2195 | if omciErr.StatusCode() != me.Success { |
| 2196 | return omciErr.GetError() |
| 2197 | } |
| 2198 | // ME needs to support Download section |
| 2199 | if !me.SupportsMsgType(meDefinition, me.DownloadSection) { |
| 2200 | return me.NewProcessingError("managed entity does not support Download Section Message-Type") |
| 2201 | } |
| 2202 | // Software Image Entity Class are always use the Software Image |
| 2203 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2204 | return me.NewProcessingError("invalid Entity Class for Download Section response") |
| 2205 | } |
Girish Gowdra | 8a7b456 | 2021-02-23 16:27:42 -0800 | [diff] [blame] | 2206 | bytes, err := b.AppendBytes(1 + len(omci.SectionData)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 2207 | if err != nil { |
| 2208 | return err |
| 2209 | } |
| 2210 | bytes[0] = omci.SectionNumber |
| 2211 | copy(bytes[1:], omci.SectionData[0:]) |
| 2212 | return nil |
| 2213 | } |
| 2214 | |
| 2215 | ///////////////////////////////////////////////////////////////////////////// |
| 2216 | // |
| 2217 | type DownloadSectionResponse struct { |
| 2218 | MeBasePacket // Note: EntityInstance for software download is two specific values |
| 2219 | Result me.Results |
| 2220 | SectionNumber byte |
| 2221 | } |
| 2222 | |
| 2223 | func (omci *DownloadSectionResponse) String() string { |
| 2224 | return fmt.Sprintf("%v, Result: %d (%v), Section #: %v", |
| 2225 | omci.MeBasePacket.String(), omci.Result, omci.Result, omci.SectionNumber) |
| 2226 | } |
| 2227 | |
| 2228 | // DecodeFromBytes decodes the given bytes of a Download Section Response into this layer |
| 2229 | func (omci *DownloadSectionResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2230 | // Common ClassID/EntityID decode in msgBase |
| 2231 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2232 | if err != nil { |
| 2233 | return err |
| 2234 | } |
| 2235 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2236 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2237 | if omciErr.StatusCode() != me.Success { |
| 2238 | return omciErr.GetError() |
| 2239 | } |
| 2240 | // ME needs to support Download section |
| 2241 | if !me.SupportsMsgType(meDefinition, me.DownloadSection) { |
| 2242 | return me.NewProcessingError("managed entity does not support Download Section Message-Type") |
| 2243 | } |
| 2244 | // Software Image Entity Class are always use the Software Image |
| 2245 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2246 | return me.NewProcessingError("invalid Entity Class for Download Section response") |
| 2247 | } |
| 2248 | omci.Result = me.Results(data[4]) |
| 2249 | if omci.Result > me.DeviceBusy { |
| 2250 | msg := fmt.Sprintf("invalid results for Download Section response: %v, must be 0..6", |
| 2251 | omci.Result) |
| 2252 | return errors.New(msg) |
| 2253 | } |
| 2254 | omci.SectionNumber = data[5] |
| 2255 | return nil |
| 2256 | } |
| 2257 | |
| 2258 | func decodeDownloadSectionResponse(data []byte, p gopacket.PacketBuilder) error { |
| 2259 | omci := &DownloadSectionResponse{} |
| 2260 | omci.MsgLayerType = LayerTypeDownloadSectionResponse |
| 2261 | return decodingLayerDecoder(omci, data, p) |
| 2262 | } |
| 2263 | |
| 2264 | // SerializeTo provides serialization of an Download Section Response message |
| 2265 | func (omci *DownloadSectionResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2266 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2267 | err := omci.MeBasePacket.SerializeTo(b) |
| 2268 | if err != nil { |
| 2269 | return err |
| 2270 | } |
| 2271 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2272 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2273 | if omciErr.StatusCode() != me.Success { |
| 2274 | return omciErr.GetError() |
| 2275 | } |
| 2276 | // ME needs to support Download section |
| 2277 | if !me.SupportsMsgType(meDefinition, me.DownloadSection) { |
| 2278 | return me.NewProcessingError("managed entity does not support Download Section Message-Type") |
| 2279 | } |
| 2280 | // Software Image Entity Class are always use the Software Image |
| 2281 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2282 | return me.NewProcessingError("invalid Entity Class for Download Section response") |
| 2283 | } |
| 2284 | bytes, err := b.AppendBytes(2) |
| 2285 | if err != nil { |
| 2286 | return err |
| 2287 | } |
| 2288 | bytes[0] = omci.SectionNumber |
| 2289 | if omci.Result > me.DeviceBusy { |
| 2290 | msg := fmt.Sprintf("invalid results for Download Section response: %v, must be 0..6", |
| 2291 | omci.Result) |
| 2292 | return errors.New(msg) |
| 2293 | } |
| 2294 | bytes[1] = byte(omci.Result) |
| 2295 | return nil |
| 2296 | } |
| 2297 | |
| 2298 | ///////////////////////////////////////////////////////////////////////////// |
| 2299 | // |
| 2300 | type EndSoftwareDownloadRequest struct { |
| 2301 | MeBasePacket // Note: EntityInstance for software download is two specific values |
| 2302 | CRC32 uint32 |
| 2303 | ImageSize uint32 |
| 2304 | NumberOfInstances byte |
| 2305 | ImageInstances []uint16 |
| 2306 | } |
| 2307 | |
| 2308 | func (omci *EndSoftwareDownloadRequest) String() string { |
| 2309 | return fmt.Sprintf("%v, CRC: %#x, Image Size: %v, Number of Instances: %v, Instances: %v", |
| 2310 | omci.MeBasePacket.String(), omci.CRC32, omci.ImageSize, omci.NumberOfInstances, omci.ImageInstances) |
| 2311 | } |
| 2312 | |
| 2313 | // DecodeFromBytes decodes the given bytes of an End Software Download Request into this layer |
| 2314 | func (omci *EndSoftwareDownloadRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2315 | // Common ClassID/EntityID decode in msgBase |
| 2316 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2317 | if err != nil { |
| 2318 | return err |
| 2319 | } |
| 2320 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2321 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2322 | if omciErr.StatusCode() != me.Success { |
| 2323 | return omciErr.GetError() |
| 2324 | } |
| 2325 | // ME needs to support End Software Download |
| 2326 | if !me.SupportsMsgType(meDefinition, me.EndSoftwareDownload) { |
| 2327 | return me.NewProcessingError("managed entity does not support End Software Download Message-Type") |
| 2328 | } |
| 2329 | // Software Image Entity Class are always use the Software Image |
| 2330 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2331 | return me.NewProcessingError("invalid Entity Class for End Software Download request") |
| 2332 | } |
| 2333 | omci.CRC32 = binary.BigEndian.Uint32(data[4:8]) |
| 2334 | omci.ImageSize = binary.BigEndian.Uint32(data[8:12]) |
| 2335 | omci.NumberOfInstances = data[13] |
| 2336 | |
| 2337 | if omci.NumberOfInstances < 1 || omci.NumberOfInstances > 9 { |
| 2338 | return me.NewProcessingError(fmt.Sprintf("invalid number of Instances: %v, must be 1..9", |
| 2339 | omci.NumberOfInstances)) |
| 2340 | } |
| 2341 | omci.ImageInstances = make([]uint16, omci.NumberOfInstances) |
| 2342 | |
| 2343 | for index := 0; index < int(omci.NumberOfInstances); index++ { |
| 2344 | omci.ImageInstances[index] = binary.BigEndian.Uint16(data[14+(index*2):]) |
| 2345 | } |
| 2346 | return nil |
| 2347 | } |
| 2348 | |
| 2349 | func decodeEndSoftwareDownloadRequest(data []byte, p gopacket.PacketBuilder) error { |
| 2350 | omci := &EndSoftwareDownloadRequest{} |
| 2351 | omci.MsgLayerType = LayerTypeEndSoftwareDownloadRequest |
| 2352 | return decodingLayerDecoder(omci, data, p) |
| 2353 | } |
| 2354 | |
| 2355 | // SerializeTo provides serialization of an End Software Download Request message |
| 2356 | func (omci *EndSoftwareDownloadRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2357 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2358 | err := omci.MeBasePacket.SerializeTo(b) |
| 2359 | if err != nil { |
| 2360 | return err |
| 2361 | } |
| 2362 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2363 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2364 | if omciErr.StatusCode() != me.Success { |
| 2365 | return omciErr.GetError() |
| 2366 | } |
| 2367 | // ME needs to support End Software Download |
| 2368 | if !me.SupportsMsgType(meDefinition, me.EndSoftwareDownload) { |
| 2369 | return me.NewProcessingError("managed entity does not support Start End Download Message-Type") |
| 2370 | } |
| 2371 | // Software Image Entity Class are always use the Software Image |
| 2372 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2373 | return me.NewProcessingError("invalid Entity Class for End Software Download response") |
| 2374 | } |
| 2375 | if omci.NumberOfInstances < 1 || omci.NumberOfInstances > 9 { |
| 2376 | return me.NewProcessingError(fmt.Sprintf("invalid number of Instances: %v, must be 1..9", |
| 2377 | omci.NumberOfInstances)) |
| 2378 | } |
| 2379 | bytes, err := b.AppendBytes(9 + (2 * int(omci.NumberOfInstances))) |
| 2380 | if err != nil { |
| 2381 | return err |
| 2382 | } |
| 2383 | binary.BigEndian.PutUint32(bytes[4:8], omci.CRC32) |
| 2384 | binary.BigEndian.PutUint32(bytes[8:12], omci.ImageSize) |
| 2385 | bytes[13] = omci.NumberOfInstances |
| 2386 | for index := 0; index < int(omci.NumberOfInstances); index++ { |
| 2387 | binary.BigEndian.PutUint16(bytes[14+(index*2):], omci.ImageInstances[index]) |
| 2388 | } |
| 2389 | return nil |
| 2390 | } |
| 2391 | |
| 2392 | ///////////////////////////////////////////////////////////////////////////// |
| 2393 | // |
| 2394 | type EndSoftwareDownloadResponse struct { |
| 2395 | MeBasePacket // Note: EntityInstance for software download is two specific values |
| 2396 | Result me.Results |
| 2397 | NumberOfInstances byte |
| 2398 | MeResults []downloadResults |
| 2399 | } |
| 2400 | |
| 2401 | func (omci *EndSoftwareDownloadResponse) String() string { |
| 2402 | return fmt.Sprintf("%v, Result: %d (%v), Number of Instances: %v, ME Results: %v", |
| 2403 | omci.MeBasePacket.String(), omci.Result, omci.Result, omci.NumberOfInstances, omci.MeResults) |
| 2404 | } |
| 2405 | |
| 2406 | // DecodeFromBytes decodes the given bytes of an End Software Download Response into this layer |
| 2407 | func (omci *EndSoftwareDownloadResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2408 | // Common ClassID/EntityID decode in msgBase |
| 2409 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2410 | if err != nil { |
| 2411 | return err |
| 2412 | } |
| 2413 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2414 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2415 | if omciErr.StatusCode() != me.Success { |
| 2416 | return omciErr.GetError() |
| 2417 | } |
| 2418 | // ME needs to support End Software Download |
| 2419 | if !me.SupportsMsgType(meDefinition, me.EndSoftwareDownload) { |
| 2420 | return me.NewProcessingError("managed entity does not support End Software Download Message-Type") |
| 2421 | } |
| 2422 | // Software Image Entity Class are always use the Software Image |
| 2423 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2424 | return me.NewProcessingError("invalid Entity Class for End Software Download response") |
| 2425 | } |
| 2426 | omci.Result = me.Results(data[4]) |
| 2427 | if omci.Result > me.DeviceBusy { |
| 2428 | msg := fmt.Sprintf("invalid results for End Software Download response: %v, must be 0..6", |
| 2429 | omci.Result) |
| 2430 | return errors.New(msg) |
| 2431 | } |
| 2432 | omci.NumberOfInstances = data[5] |
| 2433 | |
| 2434 | if omci.NumberOfInstances > 9 { |
| 2435 | msg := fmt.Sprintf("invalid number of Instances: %v, must be 0..9", |
| 2436 | omci.NumberOfInstances) |
| 2437 | return errors.New(msg) |
| 2438 | } |
| 2439 | if omci.NumberOfInstances > 0 { |
| 2440 | omci.MeResults = make([]downloadResults, omci.NumberOfInstances) |
| 2441 | |
| 2442 | for index := 0; index < int(omci.NumberOfInstances); index++ { |
| 2443 | omci.MeResults[index].ManagedEntityID = binary.BigEndian.Uint16(data[6+(index*3):]) |
| 2444 | omci.MeResults[index].Result = me.Results(data[8+(index*3)]) |
| 2445 | if omci.MeResults[index].Result > me.DeviceBusy { |
| 2446 | msg := fmt.Sprintf("invalid results for End Software Download instance %v response: %v, must be 0..6", |
| 2447 | index, omci.MeResults[index]) |
| 2448 | return errors.New(msg) |
| 2449 | } |
| 2450 | } |
| 2451 | } |
| 2452 | return nil |
| 2453 | } |
| 2454 | |
| 2455 | func decodeEndSoftwareDownloadResponse(data []byte, p gopacket.PacketBuilder) error { |
| 2456 | omci := &EndSoftwareDownloadResponse{} |
| 2457 | omci.MsgLayerType = LayerTypeEndSoftwareDownloadResponse |
| 2458 | return decodingLayerDecoder(omci, data, p) |
| 2459 | } |
| 2460 | |
| 2461 | // SerializeTo provides serialization of an End Software Download Response message |
| 2462 | func (omci *EndSoftwareDownloadResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2463 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2464 | err := omci.MeBasePacket.SerializeTo(b) |
| 2465 | if err != nil { |
| 2466 | return err |
| 2467 | } |
| 2468 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2469 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2470 | if omciErr.StatusCode() != me.Success { |
| 2471 | return omciErr.GetError() |
| 2472 | } |
| 2473 | // ME needs to support End Software Download |
| 2474 | if !me.SupportsMsgType(meDefinition, me.EndSoftwareDownload) { |
| 2475 | return me.NewProcessingError("managed entity does not support End End Download Message-Type") |
| 2476 | } |
| 2477 | // Software Image Entity Class are always use the Software Image |
| 2478 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2479 | return me.NewProcessingError("invalid Entity Class for End Download response") |
| 2480 | } |
| 2481 | bytes, err := b.AppendBytes(3 + (3 * int(omci.NumberOfInstances))) |
| 2482 | if err != nil { |
| 2483 | return err |
| 2484 | } |
| 2485 | if omci.Result > me.DeviceBusy { |
| 2486 | msg := fmt.Sprintf("invalid results for End Software Download response: %v, must be 0..6", |
| 2487 | omci.Result) |
| 2488 | return errors.New(msg) |
| 2489 | } |
| 2490 | bytes[0] = byte(omci.Result) |
| 2491 | bytes[1] = omci.NumberOfInstances |
| 2492 | |
| 2493 | if omci.NumberOfInstances > 9 { |
| 2494 | msg := fmt.Sprintf("invalid number of Instances: %v, must be 0..9", |
| 2495 | omci.NumberOfInstances) |
| 2496 | return errors.New(msg) |
| 2497 | } |
| 2498 | if omci.NumberOfInstances > 0 { |
| 2499 | for index := 0; index < int(omci.NumberOfInstances); index++ { |
| 2500 | binary.BigEndian.PutUint16(bytes[2+(3*index):], omci.MeResults[index].ManagedEntityID) |
| 2501 | |
| 2502 | if omci.MeResults[index].Result > me.DeviceBusy { |
| 2503 | msg := fmt.Sprintf("invalid results for End Software Download instance %v response: %v, must be 0..6", |
| 2504 | index, omci.MeResults[index]) |
| 2505 | return errors.New(msg) |
| 2506 | } |
| 2507 | bytes[4+(3*index)] = byte(omci.MeResults[index].Result) |
| 2508 | } |
| 2509 | } |
| 2510 | return nil |
| 2511 | } |
| 2512 | |
| 2513 | ///////////////////////////////////////////////////////////////////////////// |
| 2514 | // |
| 2515 | type ActivateSoftwareRequest struct { |
| 2516 | MeBasePacket // Note: EntityInstance for software download is two specific values |
| 2517 | ActivateFlags byte |
| 2518 | } |
| 2519 | |
| 2520 | func (omci *ActivateSoftwareRequest) String() string { |
| 2521 | return fmt.Sprintf("%v, Flags: %#x", |
| 2522 | omci.MeBasePacket.String(), omci.ActivateFlags) |
| 2523 | } |
| 2524 | |
| 2525 | // DecodeFromBytes decodes the given bytes of an Activate Software Request into this layer |
| 2526 | func (omci *ActivateSoftwareRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2527 | // Common ClassID/EntityID decode in msgBase |
| 2528 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2529 | if err != nil { |
| 2530 | return err |
| 2531 | } |
| 2532 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2533 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2534 | if omciErr.StatusCode() != me.Success { |
| 2535 | return omciErr.GetError() |
| 2536 | } |
| 2537 | // ME needs to support End Software Download |
| 2538 | if !me.SupportsMsgType(meDefinition, me.ActivateSoftware) { |
| 2539 | return me.NewProcessingError("managed entity does not support Activate Software Message-Type") |
| 2540 | } |
| 2541 | // Software Image Entity Class are always use the Software Image |
| 2542 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2543 | return me.NewProcessingError("invalid Entity Class for Activate Software request") |
| 2544 | } |
| 2545 | omci.ActivateFlags = data[4] |
| 2546 | if omci.ActivateFlags > 2 { |
| 2547 | return me.NewProcessingError(fmt.Sprintf("invalid number of Activation flangs: %v, must be 0..2", |
| 2548 | omci.ActivateFlags)) |
| 2549 | } |
| 2550 | return nil |
| 2551 | } |
| 2552 | |
| 2553 | func decodeActivateSoftwareRequest(data []byte, p gopacket.PacketBuilder) error { |
| 2554 | omci := &ActivateSoftwareRequest{} |
| 2555 | omci.MsgLayerType = LayerTypeActivateSoftwareRequest |
| 2556 | return decodingLayerDecoder(omci, data, p) |
| 2557 | } |
| 2558 | |
| 2559 | // SerializeTo provides serialization of an Activate Software message |
| 2560 | func (omci *ActivateSoftwareRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2561 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2562 | err := omci.MeBasePacket.SerializeTo(b) |
| 2563 | if err != nil { |
| 2564 | return err |
| 2565 | } |
| 2566 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2567 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2568 | if omciErr.StatusCode() != me.Success { |
| 2569 | return omciErr.GetError() |
| 2570 | } |
| 2571 | // ME needs to support End Software Download |
| 2572 | if !me.SupportsMsgType(meDefinition, me.ActivateSoftware) { |
| 2573 | return me.NewProcessingError("managed entity does not support Activate Message-Type") |
| 2574 | } |
| 2575 | // Software Image Entity Class are always use the Software Image |
| 2576 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2577 | return me.NewProcessingError("invalid Entity Class for Activate Software request") |
| 2578 | } |
| 2579 | bytes, err := b.AppendBytes(1) |
| 2580 | if err != nil { |
| 2581 | return err |
| 2582 | } |
| 2583 | bytes[0] = omci.ActivateFlags |
| 2584 | if omci.ActivateFlags > 2 { |
| 2585 | msg := fmt.Sprintf("invalid results for Activate Software request: %v, must be 0..2", |
| 2586 | omci.ActivateFlags) |
| 2587 | return errors.New(msg) |
| 2588 | } |
| 2589 | return nil |
| 2590 | } |
| 2591 | |
| 2592 | ///////////////////////////////////////////////////////////////////////////// |
| 2593 | // |
| 2594 | type ActivateSoftwareResponse struct { |
| 2595 | MeBasePacket |
| 2596 | Result me.Results |
| 2597 | } |
| 2598 | |
| 2599 | func (omci *ActivateSoftwareResponse) String() string { |
| 2600 | return fmt.Sprintf("%v, Result: %d (%v)", |
| 2601 | omci.MeBasePacket.String(), omci.Result, omci.Result) |
| 2602 | } |
| 2603 | |
| 2604 | // DecodeFromBytes decodes the given bytes of an Activate Softwre Response into this layer |
| 2605 | func (omci *ActivateSoftwareResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2606 | // Common ClassID/EntityID decode in msgBase |
| 2607 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2608 | if err != nil { |
| 2609 | return err |
| 2610 | } |
| 2611 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2612 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2613 | if omciErr.StatusCode() != me.Success { |
| 2614 | return omciErr.GetError() |
| 2615 | } |
| 2616 | // ME needs to support End Software Download |
| 2617 | if !me.SupportsMsgType(meDefinition, me.ActivateSoftware) { |
| 2618 | return me.NewProcessingError("managed entity does not support Activate Software Message-Type") |
| 2619 | } |
| 2620 | // Software Image Entity Class are always use the Software Image |
| 2621 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2622 | return me.NewProcessingError("invalid Entity Class for Activate Software response") |
| 2623 | } |
| 2624 | omci.Result = me.Results(data[4]) |
| 2625 | if omci.Result > me.Results(6) { |
| 2626 | msg := fmt.Sprintf("invalid results for Activate Software response: %v, must be 0..6", |
| 2627 | omci.Result) |
| 2628 | return errors.New(msg) |
| 2629 | } |
| 2630 | return nil |
| 2631 | } |
| 2632 | |
| 2633 | func decodeActivateSoftwareResponse(data []byte, p gopacket.PacketBuilder) error { |
| 2634 | omci := &ActivateSoftwareResponse{} |
| 2635 | omci.MsgLayerType = LayerTypeActivateSoftwareResponse |
| 2636 | return decodingLayerDecoder(omci, data, p) |
| 2637 | } |
| 2638 | |
| 2639 | // SerializeTo provides serialization of an Activate Software Response message |
| 2640 | func (omci *ActivateSoftwareResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2641 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2642 | err := omci.MeBasePacket.SerializeTo(b) |
| 2643 | if err != nil { |
| 2644 | return err |
| 2645 | } |
| 2646 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2647 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2648 | if omciErr.StatusCode() != me.Success { |
| 2649 | return omciErr.GetError() |
| 2650 | } |
| 2651 | // ME needs to support End Software Download |
| 2652 | if !me.SupportsMsgType(meDefinition, me.ActivateSoftware) { |
| 2653 | return me.NewProcessingError("managed entity does not support Activate Message-Type") |
| 2654 | } |
| 2655 | // Software Image Entity Class are always use the Software Image |
| 2656 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2657 | return me.NewProcessingError("invalid Entity Class for Activate Software response") |
| 2658 | } |
| 2659 | bytes, err := b.AppendBytes(1) |
| 2660 | if err != nil { |
| 2661 | return err |
| 2662 | } |
| 2663 | bytes[0] = byte(omci.Result) |
| 2664 | if omci.Result > me.Results(6) { |
| 2665 | msg := fmt.Sprintf("invalid results for Activate Software response: %v, must be 0..6", |
| 2666 | omci.Result) |
| 2667 | return errors.New(msg) |
| 2668 | } |
| 2669 | return nil |
| 2670 | } |
| 2671 | |
| 2672 | ///////////////////////////////////////////////////////////////////////////// |
| 2673 | // |
| 2674 | type CommitSoftwareRequest struct { |
| 2675 | MeBasePacket |
| 2676 | } |
| 2677 | |
| 2678 | func (omci *CommitSoftwareRequest) String() string { |
| 2679 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 2680 | } |
| 2681 | |
| 2682 | // DecodeFromBytes decodes the given bytes of a Commit Software Request into this layer |
| 2683 | func (omci *CommitSoftwareRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2684 | // Common ClassID/EntityID decode in msgBase |
| 2685 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2686 | if err != nil { |
| 2687 | return err |
| 2688 | } |
| 2689 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2690 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2691 | if omciErr.StatusCode() != me.Success { |
| 2692 | return omciErr.GetError() |
| 2693 | } |
| 2694 | // ME needs to support End Software Download |
| 2695 | if !me.SupportsMsgType(meDefinition, me.CommitSoftware) { |
| 2696 | return me.NewProcessingError("managed entity does not support Commit Software Message-Type") |
| 2697 | } |
| 2698 | // Software Image Entity Class are always use the Software Image |
| 2699 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2700 | return me.NewProcessingError("invalid Entity Class for Commit Software request") |
| 2701 | } |
| 2702 | return nil |
| 2703 | } |
| 2704 | |
| 2705 | func decodeCommitSoftwareRequest(data []byte, p gopacket.PacketBuilder) error { |
| 2706 | omci := &CommitSoftwareRequest{} |
| 2707 | omci.MsgLayerType = LayerTypeCommitSoftwareRequest |
| 2708 | return decodingLayerDecoder(omci, data, p) |
| 2709 | } |
| 2710 | |
| 2711 | // SerializeTo provides serialization of an Commit Software Request message |
| 2712 | func (omci *CommitSoftwareRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2713 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2714 | err := omci.MeBasePacket.SerializeTo(b) |
| 2715 | if err != nil { |
| 2716 | return err |
| 2717 | } |
| 2718 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2719 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2720 | if omciErr.StatusCode() != me.Success { |
| 2721 | return omciErr.GetError() |
| 2722 | } |
| 2723 | // ME needs to support End Software Download |
| 2724 | if !me.SupportsMsgType(meDefinition, me.CommitSoftware) { |
| 2725 | return me.NewProcessingError("managed entity does not support Commit Message-Type") |
| 2726 | } |
| 2727 | // Software Image Entity Class are always use the Software Image |
| 2728 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2729 | return me.NewProcessingError("invalid Entity Class for Commit Software request") |
| 2730 | } |
| 2731 | return nil |
| 2732 | } |
| 2733 | |
| 2734 | ///////////////////////////////////////////////////////////////////////////// |
| 2735 | // |
| 2736 | type CommitSoftwareResponse struct { |
| 2737 | MeBasePacket |
| 2738 | } |
| 2739 | |
| 2740 | func (omci *CommitSoftwareResponse) String() string { |
| 2741 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 2742 | } |
| 2743 | |
| 2744 | // DecodeFromBytes decodes the given bytes of a Commit Softwar Response into this layer |
| 2745 | func (omci *CommitSoftwareResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2746 | // Common ClassID/EntityID decode in msgBase |
| 2747 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2748 | if err != nil { |
| 2749 | return err |
| 2750 | } |
| 2751 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2752 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2753 | if omciErr.StatusCode() != me.Success { |
| 2754 | return omciErr.GetError() |
| 2755 | } |
| 2756 | // ME needs to support End Software Download |
| 2757 | if !me.SupportsMsgType(meDefinition, me.CommitSoftware) { |
| 2758 | return me.NewProcessingError("managed entity does not support Commit Software Message-Type") |
| 2759 | } |
| 2760 | // Software Image Entity Class are always use the Software Image |
| 2761 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2762 | return me.NewProcessingError("invalid Entity Class for Commit Software response") |
| 2763 | } |
| 2764 | return nil |
| 2765 | } |
| 2766 | |
| 2767 | func decodeCommitSoftwareResponse(data []byte, p gopacket.PacketBuilder) error { |
| 2768 | omci := &CommitSoftwareResponse{} |
| 2769 | omci.MsgLayerType = LayerTypeCommitSoftwareResponse |
| 2770 | return decodingLayerDecoder(omci, data, p) |
| 2771 | } |
| 2772 | |
| 2773 | // SerializeTo provides serialization of an Commit Software Response message |
| 2774 | func (omci *CommitSoftwareResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2775 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2776 | err := omci.MeBasePacket.SerializeTo(b) |
| 2777 | if err != nil { |
| 2778 | return err |
| 2779 | } |
| 2780 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2781 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2782 | if omciErr.StatusCode() != me.Success { |
| 2783 | return omciErr.GetError() |
| 2784 | } |
| 2785 | // ME needs to support End Software Download |
| 2786 | if !me.SupportsMsgType(meDefinition, me.CommitSoftware) { |
| 2787 | return me.NewProcessingError("managed entity does not support Commit Message-Type") |
| 2788 | } |
| 2789 | // Software Image Entity Class are always use the Software Image |
| 2790 | if omci.EntityClass != me.SoftwareImageClassID { |
| 2791 | return me.NewProcessingError("invalid Entity Class for Commit Software response") |
| 2792 | } |
| 2793 | return nil |
| 2794 | } |
| 2795 | |
| 2796 | ///////////////////////////////////////////////////////////////////////////// |
| 2797 | // |
| 2798 | type SynchronizeTimeRequest struct { |
| 2799 | MeBasePacket |
| 2800 | Year uint16 |
| 2801 | Month uint8 |
| 2802 | Day uint8 |
| 2803 | Hour uint8 |
| 2804 | Minute uint8 |
| 2805 | Second uint8 |
| 2806 | } |
| 2807 | |
| 2808 | func (omci *SynchronizeTimeRequest) String() string { |
| 2809 | return fmt.Sprintf("%v, Date-Time: %d/%d/%d-%02d:%02d:%02d", |
| 2810 | omci.MeBasePacket.String(), omci.Year, omci.Month, omci.Day, omci.Hour, omci.Minute, omci.Second) |
| 2811 | } |
| 2812 | |
| 2813 | // DecodeFromBytes decodes the given bytes of a Synchronize Time Request into this layer |
| 2814 | func (omci *SynchronizeTimeRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2815 | // Common ClassID/EntityID decode in msgBase |
| 2816 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2817 | if err != nil { |
| 2818 | return err |
| 2819 | } |
| 2820 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2821 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2822 | if omciErr.StatusCode() != me.Success { |
| 2823 | return omciErr.GetError() |
| 2824 | } |
| 2825 | // ME needs to support Synchronize Time |
| 2826 | if !me.SupportsMsgType(meDefinition, me.SynchronizeTime) { |
| 2827 | return me.NewProcessingError("managed entity does not support Synchronize Time Message-Type") |
| 2828 | } |
| 2829 | // Synchronize Time Entity Class are always ONU-G (256) and Entity Instance of 0 |
| 2830 | if omci.EntityClass != me.OnuGClassID { |
| 2831 | return me.NewProcessingError("invalid Entity Class for Synchronize Time request") |
| 2832 | } |
| 2833 | if omci.EntityInstance != 0 { |
| 2834 | return me.NewUnknownInstanceError("invalid Entity Instance for Synchronize Time request") |
| 2835 | } |
| 2836 | omci.Year = binary.BigEndian.Uint16(data[4:6]) |
| 2837 | omci.Month = data[6] |
| 2838 | omci.Day = data[7] |
| 2839 | omci.Hour = data[8] |
| 2840 | omci.Minute = data[9] |
| 2841 | omci.Second = data[10] |
| 2842 | return nil |
| 2843 | } |
| 2844 | |
| 2845 | func decodeSynchronizeTimeRequest(data []byte, p gopacket.PacketBuilder) error { |
| 2846 | omci := &SynchronizeTimeRequest{} |
| 2847 | omci.MsgLayerType = LayerTypeSynchronizeTimeRequest |
| 2848 | return decodingLayerDecoder(omci, data, p) |
| 2849 | } |
| 2850 | |
| 2851 | // SerializeTo provides serialization of an Synchronize Time Request message |
| 2852 | func (omci *SynchronizeTimeRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2853 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2854 | err := omci.MeBasePacket.SerializeTo(b) |
| 2855 | if err != nil { |
| 2856 | return err |
| 2857 | } |
| 2858 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2859 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2860 | if omciErr.StatusCode() != me.Success { |
| 2861 | return omciErr.GetError() |
| 2862 | } |
| 2863 | // ME needs to support Synchronize Time |
| 2864 | if !me.SupportsMsgType(entity, me.SynchronizeTime) { |
| 2865 | return me.NewProcessingError("managed entity does not support the Synchronize Time Message-Type") |
| 2866 | } |
| 2867 | bytes, err := b.AppendBytes(7) |
| 2868 | if err != nil { |
| 2869 | return err |
| 2870 | } |
| 2871 | binary.BigEndian.PutUint16(bytes[0:2], omci.Year) |
| 2872 | bytes[2] = omci.Month |
| 2873 | bytes[3] = omci.Day |
| 2874 | bytes[4] = omci.Hour |
| 2875 | bytes[5] = omci.Minute |
| 2876 | bytes[6] = omci.Second |
| 2877 | return nil |
| 2878 | } |
| 2879 | |
| 2880 | ///////////////////////////////////////////////////////////////////////////// |
| 2881 | // |
| 2882 | type SynchronizeTimeResponse struct { |
| 2883 | MeBasePacket |
| 2884 | Result me.Results |
| 2885 | SuccessResults uint8 // Only if 'Result' is 0 -> success |
| 2886 | } |
| 2887 | |
| 2888 | func (omci *SynchronizeTimeResponse) String() string { |
| 2889 | return fmt.Sprintf("%v, Results: %d (%v), Success: %d", |
| 2890 | omci.MeBasePacket.String(), omci.Result, omci.Result, omci.SuccessResults) |
| 2891 | } |
| 2892 | |
| 2893 | // DecodeFromBytes decodes the given bytes of a Synchronize Time Response into this layer |
| 2894 | func (omci *SynchronizeTimeResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2895 | // Common ClassID/EntityID decode in msgBase |
| 2896 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2897 | if err != nil { |
| 2898 | return err |
| 2899 | } |
| 2900 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2901 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2902 | if omciErr.StatusCode() != me.Success { |
| 2903 | return omciErr.GetError() |
| 2904 | } |
| 2905 | // ME needs to support Synchronize Time |
| 2906 | if !me.SupportsMsgType(meDefinition, me.SynchronizeTime) { |
| 2907 | return me.NewProcessingError("managed entity does not support Synchronize Time Message-Type") |
| 2908 | } |
| 2909 | // Synchronize Time Entity Class are always ONU-G (256) and Entity Instance of 0 |
| 2910 | if omci.EntityClass != me.OnuGClassID { |
| 2911 | return me.NewProcessingError("invalid Entity Class for Synchronize Time response") |
| 2912 | } |
| 2913 | if omci.EntityInstance != 0 { |
| 2914 | return me.NewUnknownInstanceError("invalid Entity Instance for Synchronize Time response") |
| 2915 | } |
| 2916 | omci.Result = me.Results(data[4]) |
| 2917 | if omci.Result > me.DeviceBusy { |
| 2918 | msg := fmt.Sprintf("invalid results code: %v, must be 0..8", omci.Result) |
| 2919 | return errors.New(msg) |
| 2920 | } |
| 2921 | omci.SuccessResults = data[5] |
| 2922 | return nil |
| 2923 | } |
| 2924 | |
| 2925 | func decodeSynchronizeTimeResponse(data []byte, p gopacket.PacketBuilder) error { |
| 2926 | omci := &SynchronizeTimeResponse{} |
| 2927 | omci.MsgLayerType = LayerTypeSynchronizeTimeResponse |
| 2928 | return decodingLayerDecoder(omci, data, p) |
| 2929 | } |
| 2930 | |
| 2931 | // SerializeTo provides serialization of an Synchronize Time Response message |
| 2932 | func (omci *SynchronizeTimeResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 2933 | // Basic (common) OMCI Header is 8 octets, 10 |
| 2934 | err := omci.MeBasePacket.SerializeTo(b) |
| 2935 | if err != nil { |
| 2936 | return err |
| 2937 | } |
| 2938 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2939 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2940 | if omciErr.StatusCode() != me.Success { |
| 2941 | return omciErr.GetError() |
| 2942 | } |
| 2943 | // Synchronize Time Entity Class are always ONU DATA (2) and Entity Instance of 0 |
| 2944 | if omci.EntityClass != me.OnuGClassID { |
| 2945 | return me.NewProcessingError("invalid Entity Class for Synchronize Time response") |
| 2946 | } |
| 2947 | if omci.EntityInstance != 0 { |
| 2948 | return me.NewUnknownInstanceError("invalid Entity Instance for Synchronize Time response") |
| 2949 | } |
| 2950 | // ME needs to support Synchronize Time |
| 2951 | if !me.SupportsMsgType(entity, me.SynchronizeTime) { |
| 2952 | return me.NewProcessingError("managed entity does not support the Synchronize Time Message-Type") |
| 2953 | } |
| 2954 | numBytes := 2 |
| 2955 | if omci.Result != me.Success { |
| 2956 | numBytes = 1 |
| 2957 | } |
| 2958 | bytes, err := b.AppendBytes(numBytes) |
| 2959 | if err != nil { |
| 2960 | return err |
| 2961 | } |
| 2962 | bytes[0] = uint8(omci.Result) |
| 2963 | if omci.Result == me.Success { |
| 2964 | bytes[1] = omci.SuccessResults |
| 2965 | } |
| 2966 | return nil |
| 2967 | } |
| 2968 | |
| 2969 | ///////////////////////////////////////////////////////////////////////////// |
| 2970 | // |
| 2971 | type RebootRequest struct { |
| 2972 | MeBasePacket |
| 2973 | RebootCondition byte |
| 2974 | } |
| 2975 | |
| 2976 | func (omci *RebootRequest) String() string { |
| 2977 | return fmt.Sprintf("%v, Reboot Condition: %v", |
| 2978 | omci.MeBasePacket.String(), omci.RebootCondition) |
| 2979 | } |
| 2980 | |
| 2981 | // DecodeFromBytes decodes the given bytes of a Reboot Request into this layer |
| 2982 | func (omci *RebootRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 2983 | // Common ClassID/EntityID decode in msgBase |
| 2984 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 2985 | if err != nil { |
| 2986 | return err |
| 2987 | } |
| 2988 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 2989 | me.ParamData{EntityID: omci.EntityInstance}) |
| 2990 | if omciErr.StatusCode() != me.Success { |
| 2991 | return omciErr.GetError() |
| 2992 | } |
| 2993 | // ME needs to support Reboot |
| 2994 | if !me.SupportsMsgType(meDefinition, me.Reboot) { |
| 2995 | return me.NewProcessingError("managed entity does not support Reboot Message-Type") |
| 2996 | } |
| 2997 | omci.RebootCondition = data[4] |
| 2998 | if omci.RebootCondition > 3 { |
| 2999 | msg := fmt.Sprintf("invalid reboot condition code: %v, must be 0..3", omci.RebootCondition) |
| 3000 | return errors.New(msg) |
| 3001 | } |
| 3002 | return nil |
| 3003 | } |
| 3004 | |
| 3005 | func decodeRebootRequest(data []byte, p gopacket.PacketBuilder) error { |
| 3006 | omci := &RebootRequest{} |
| 3007 | omci.MsgLayerType = LayerTypeRebootRequest |
| 3008 | return decodingLayerDecoder(omci, data, p) |
| 3009 | } |
| 3010 | |
| 3011 | // SerializeTo provides serialization of an Reboot Request message |
| 3012 | func (omci *RebootRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3013 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3014 | err := omci.MeBasePacket.SerializeTo(b) |
| 3015 | if err != nil { |
| 3016 | return err |
| 3017 | } |
| 3018 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3019 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3020 | if omciErr.StatusCode() != me.Success { |
| 3021 | return omciErr.GetError() |
| 3022 | } |
| 3023 | // ME needs to support Reboot |
| 3024 | if !me.SupportsMsgType(entity, me.Reboot) { |
| 3025 | return me.NewProcessingError("managed entity does not support the Synchronize Time Message-Type") |
| 3026 | } |
| 3027 | bytes, err := b.AppendBytes(1) |
| 3028 | if err != nil { |
| 3029 | return err |
| 3030 | } |
| 3031 | if omci.RebootCondition > 3 { |
| 3032 | return me.NewProcessingError(fmt.Sprintf("invalid reboot condition code: %v, must be 0..3", |
| 3033 | omci.RebootCondition)) |
| 3034 | } |
| 3035 | bytes[0] = omci.RebootCondition |
| 3036 | return nil |
| 3037 | } |
| 3038 | |
| 3039 | ///////////////////////////////////////////////////////////////////////////// |
| 3040 | // |
| 3041 | type RebootResponse struct { |
| 3042 | MeBasePacket |
| 3043 | Result me.Results |
| 3044 | } |
| 3045 | |
| 3046 | // DecodeFromBytes decodes the given bytes of a Reboot Response into this layer |
| 3047 | func (omci *RebootResponse) String() string { |
| 3048 | return fmt.Sprintf("%v, Result: %d (%v)", |
| 3049 | omci.MeBasePacket.String(), omci.Result, omci.Result) |
| 3050 | } |
| 3051 | |
| 3052 | // DecodeFromBytes decodes the given bytes of a Reboot Response into this layer |
| 3053 | func (omci *RebootResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3054 | // Common ClassID/EntityID decode in msgBase |
| 3055 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 3056 | if err != nil { |
| 3057 | return err |
| 3058 | } |
| 3059 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3060 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3061 | if omciErr.StatusCode() != me.Success { |
| 3062 | return omciErr.GetError() |
| 3063 | } |
| 3064 | // ME needs to support Reboot |
| 3065 | if !me.SupportsMsgType(meDefinition, me.Reboot) { |
| 3066 | return me.NewProcessingError("managed entity does not support Reboot Message-Type") |
| 3067 | } |
| 3068 | if omci.Result > 6 { |
| 3069 | msg := fmt.Sprintf("invalid reboot results code: %v, must be 0..6", omci.Result) |
| 3070 | return errors.New(msg) |
| 3071 | } |
| 3072 | omci.Result = me.Results(data[4]) |
| 3073 | return nil |
| 3074 | } |
| 3075 | |
| 3076 | func decodeRebootResponse(data []byte, p gopacket.PacketBuilder) error { |
| 3077 | omci := &RebootResponse{} |
| 3078 | omci.MsgLayerType = LayerTypeRebootResponse |
| 3079 | return decodingLayerDecoder(omci, data, p) |
| 3080 | } |
| 3081 | |
| 3082 | // SerializeTo provides serialization of an Reboot Response message |
| 3083 | func (omci *RebootResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3084 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3085 | err := omci.MeBasePacket.SerializeTo(b) |
| 3086 | if err != nil { |
| 3087 | return err |
| 3088 | } |
| 3089 | entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3090 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3091 | if omciErr.StatusCode() != me.Success { |
| 3092 | return omciErr.GetError() |
| 3093 | } |
| 3094 | // ME needs to support Reboot |
| 3095 | if !me.SupportsMsgType(entity, me.Reboot) { |
| 3096 | return me.NewProcessingError("managed entity does not support the Synchronize Time Message-Type") |
| 3097 | } |
| 3098 | bytes, err := b.AppendBytes(1) |
| 3099 | if err != nil { |
| 3100 | return err |
| 3101 | } |
| 3102 | if omci.Result > 6 { |
| 3103 | msg := fmt.Sprintf("invalid reboot results code: %v, must be 0..6", omci.Result) |
| 3104 | return errors.New(msg) |
| 3105 | } |
| 3106 | bytes[0] = byte(omci.Result) |
| 3107 | return nil |
| 3108 | } |
| 3109 | |
| 3110 | ///////////////////////////////////////////////////////////////////////////// |
| 3111 | // |
| 3112 | type GetNextRequest struct { |
| 3113 | MeBasePacket |
| 3114 | AttributeMask uint16 |
| 3115 | SequenceNumber uint16 |
| 3116 | } |
| 3117 | |
| 3118 | func (omci *GetNextRequest) String() string { |
| 3119 | return fmt.Sprintf("%v, Attribute Mask: %#x, Sequence Number: %v", |
| 3120 | omci.MeBasePacket.String(), omci.AttributeMask, omci.SequenceNumber) |
| 3121 | } |
| 3122 | |
| 3123 | // DecodeFromBytes decodes the given bytes of a Get Next Request into this layer |
| 3124 | func (omci *GetNextRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3125 | // Common ClassID/EntityID decode in msgBase |
| 3126 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 3127 | if err != nil { |
| 3128 | return err |
| 3129 | } |
| 3130 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3131 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3132 | if omciErr.StatusCode() != me.Success { |
| 3133 | return omciErr.GetError() |
| 3134 | } |
| 3135 | // ME needs to support GetNext |
| 3136 | if !me.SupportsMsgType(meDefinition, me.GetNext) { |
| 3137 | return me.NewProcessingError("managed entity does not support Get Next Message-Type") |
| 3138 | } |
| 3139 | // Note: G.988 specifies that an error code of (3) should result if more |
| 3140 | // than one attribute is requested |
| 3141 | // TODO: Return error. Have flag to optionally allow it to be encoded |
| 3142 | // TODO: Check that the attribute is a table attirbute. Issue warning or return error |
| 3143 | omci.AttributeMask = binary.BigEndian.Uint16(data[4:6]) |
| 3144 | omci.SequenceNumber = binary.BigEndian.Uint16(data[6:8]) |
| 3145 | return nil |
| 3146 | } |
| 3147 | |
| 3148 | func decodeGetNextRequest(data []byte, p gopacket.PacketBuilder) error { |
| 3149 | omci := &GetNextRequest{} |
| 3150 | omci.MsgLayerType = LayerTypeGetNextRequest |
| 3151 | return decodingLayerDecoder(omci, data, p) |
| 3152 | } |
| 3153 | |
| 3154 | // SerializeTo provides serialization of an Get Next Message Type Request |
| 3155 | func (omci *GetNextRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3156 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3157 | err := omci.MeBasePacket.SerializeTo(b) |
| 3158 | if err != nil { |
| 3159 | return err |
| 3160 | } |
| 3161 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3162 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3163 | if omciErr.StatusCode() != me.Success { |
| 3164 | return omciErr.GetError() |
| 3165 | } |
| 3166 | // ME needs to support GetNext |
| 3167 | if !me.SupportsMsgType(meDefinition, me.GetNext) { |
| 3168 | return me.NewProcessingError("managed entity does not support Get Next Message-Type") |
| 3169 | } |
| 3170 | bytes, err := b.AppendBytes(4) |
| 3171 | if err != nil { |
| 3172 | return err |
| 3173 | } |
| 3174 | binary.BigEndian.PutUint16(bytes, omci.AttributeMask) |
| 3175 | binary.BigEndian.PutUint16(bytes[2:], omci.SequenceNumber) |
| 3176 | return nil |
| 3177 | } |
| 3178 | |
| 3179 | ///////////////////////////////////////////////////////////////////////////// |
| 3180 | // |
| 3181 | type GetNextResponse struct { |
| 3182 | MeBasePacket |
| 3183 | Result me.Results |
| 3184 | AttributeMask uint16 |
| 3185 | Attributes me.AttributeValueMap |
| 3186 | } |
| 3187 | |
| 3188 | // SerializeTo provides serialization of an Get Next Message Type Response |
| 3189 | func (omci *GetNextResponse) String() string { |
| 3190 | return fmt.Sprintf("%v, Result: %v, Attribute Mask: %#x, Attributes: %v", |
| 3191 | omci.MeBasePacket.String(), omci.Result, omci.AttributeMask, omci.Attributes) |
| 3192 | } |
| 3193 | |
| 3194 | // DecodeFromBytes decodes the given bytes of a Get Next Response into this layer |
| 3195 | func (omci *GetNextResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3196 | // Common ClassID/EntityID decode in msgBase |
| 3197 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 3198 | if err != nil { |
| 3199 | return err |
| 3200 | } |
| 3201 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3202 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3203 | if omciErr.StatusCode() != me.Success { |
| 3204 | return omciErr.GetError() |
| 3205 | } |
| 3206 | // ME needs to support Set |
| 3207 | if !me.SupportsMsgType(meDefinition, me.GetNext) { |
| 3208 | return me.NewProcessingError("managed entity does not support Get Next Message-Type") |
| 3209 | } |
| 3210 | omci.Result = me.Results(data[4]) |
| 3211 | if omci.Result > 6 { |
| 3212 | msg := fmt.Sprintf("invalid get next results code: %v, must be 0..6", omci.Result) |
| 3213 | return errors.New(msg) |
| 3214 | } |
| 3215 | omci.AttributeMask = binary.BigEndian.Uint16(data[5:7]) |
| 3216 | |
| 3217 | // Attribute decode |
| 3218 | omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[7:], p, byte(GetNextResponseType)) |
| 3219 | if err != nil { |
| 3220 | return err |
| 3221 | } |
| 3222 | // Validate all attributes support read |
| 3223 | for attrName := range omci.Attributes { |
| 3224 | attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName) |
| 3225 | if err != nil { |
| 3226 | return err |
| 3227 | } |
| 3228 | if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Read) { |
| 3229 | msg := fmt.Sprintf("attribute '%v' does not support read access", attrName) |
| 3230 | return me.NewProcessingError(msg) |
| 3231 | } |
| 3232 | } |
| 3233 | if eidDef, eidDefOK := meDefinition.GetAttributeDefinitions()[0]; eidDefOK { |
| 3234 | omci.Attributes[eidDef.GetName()] = omci.EntityInstance |
| 3235 | return nil |
| 3236 | } |
| 3237 | panic("All Managed Entities have an EntityID attribute") |
| 3238 | } |
| 3239 | |
| 3240 | func decodeGetNextResponse(data []byte, p gopacket.PacketBuilder) error { |
| 3241 | omci := &GetNextResponse{} |
| 3242 | omci.MsgLayerType = LayerTypeGetNextResponse |
| 3243 | return decodingLayerDecoder(omci, data, p) |
| 3244 | } |
| 3245 | |
| 3246 | // SerializeTo provides serialization of an Get Next Message Type Response |
| 3247 | func (omci *GetNextResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3248 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3249 | err := omci.MeBasePacket.SerializeTo(b) |
| 3250 | if err != nil { |
| 3251 | return err |
| 3252 | } |
| 3253 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3254 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3255 | if omciErr.StatusCode() != me.Success { |
| 3256 | return omciErr.GetError() |
| 3257 | } |
| 3258 | // ME needs to support Get |
| 3259 | if !me.SupportsMsgType(meDefinition, me.GetNext) { |
| 3260 | return me.NewProcessingError("managed entity does not support the Get Next Message-Type") |
| 3261 | } |
| 3262 | bytes, err := b.AppendBytes(3) |
| 3263 | if err != nil { |
| 3264 | return err |
| 3265 | } |
| 3266 | bytes[0] = byte(omci.Result) |
| 3267 | if omci.Result > 6 { |
| 3268 | msg := fmt.Sprintf("invalid get next results code: %v, must be 0..6", omci.Result) |
| 3269 | return errors.New(msg) |
| 3270 | } |
| 3271 | binary.BigEndian.PutUint16(bytes[1:3], omci.AttributeMask) |
| 3272 | |
| 3273 | // Validate all attributes support read |
| 3274 | for attrName := range omci.Attributes { |
| 3275 | attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName) |
| 3276 | if err != nil { |
| 3277 | return err |
| 3278 | } |
| 3279 | if attr.Index != 0 && !me.SupportsAttributeAccess(*attr, me.Read) { |
| 3280 | msg := fmt.Sprintf("attribute '%v' does not support read access", attrName) |
| 3281 | return me.NewProcessingError(msg) |
| 3282 | } |
| 3283 | } |
| 3284 | // Attribute serialization |
| 3285 | switch omci.Result { |
| 3286 | default: |
| 3287 | break |
| 3288 | |
| 3289 | case me.Success: |
| 3290 | // TODO: Only Baseline supported at this time |
| 3291 | bytesAvailable := MaxBaselineLength - 11 - 8 |
| 3292 | |
| 3293 | err, _ = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b, |
| 3294 | byte(GetNextResponseType), bytesAvailable, false) |
| 3295 | if err != nil { |
| 3296 | return err |
| 3297 | } |
| 3298 | } |
| 3299 | return nil |
| 3300 | } |
| 3301 | |
| 3302 | ///////////////////////////////////////////////////////////////////////////// |
| 3303 | // |
| 3304 | type TestResultMsg struct { |
| 3305 | MeBasePacket |
| 3306 | } |
| 3307 | |
| 3308 | func (omci *TestResultMsg) String() string { |
| 3309 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 3310 | } |
| 3311 | |
| 3312 | // DecodeFromBytes decodes the given bytes of a Test Result Notification into this layer |
| 3313 | func (omci *TestResultMsg) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3314 | // Common ClassID/EntityID decode in msgBase |
| 3315 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 3316 | if err != nil { |
| 3317 | return err |
| 3318 | } |
| 3319 | return errors.New("need to implement") // TODO: Fix me) // return nil |
| 3320 | } |
| 3321 | |
| 3322 | func decodeTestResult(data []byte, p gopacket.PacketBuilder) error { |
| 3323 | omci := &TestResultMsg{} |
| 3324 | omci.MsgLayerType = LayerTypeTestResult |
| 3325 | return decodingLayerDecoder(omci, data, p) |
| 3326 | } |
| 3327 | |
| 3328 | // SerializeTo provides serialization of an Test Result notification message |
| 3329 | func (omci *TestResultMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3330 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3331 | err := omci.MeBasePacket.SerializeTo(b) |
| 3332 | if err != nil { |
| 3333 | return err |
| 3334 | } |
| 3335 | return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b) |
| 3336 | } |
| 3337 | |
| 3338 | ///////////////////////////////////////////////////////////////////////////// |
| 3339 | // |
| 3340 | type GetCurrentDataRequest struct { |
| 3341 | MeBasePacket |
| 3342 | AttributeMask uint16 |
| 3343 | } |
| 3344 | |
| 3345 | func (omci *GetCurrentDataRequest) String() string { |
| 3346 | return fmt.Sprintf("%v, Attribute Mask: %#x", |
| 3347 | omci.MeBasePacket.String(), omci.AttributeMask) |
| 3348 | } |
| 3349 | |
| 3350 | // DecodeFromBytes decodes the given bytes of a Get Current Data Request into this layer |
| 3351 | func (omci *GetCurrentDataRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3352 | // Common ClassID/EntityID decode in msgBase |
| 3353 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 3354 | if err != nil { |
| 3355 | return err |
| 3356 | } |
| 3357 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3358 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3359 | if omciErr.StatusCode() != me.Success { |
| 3360 | return omciErr.GetError() |
| 3361 | } |
| 3362 | // ME needs to support GetNext |
| 3363 | if !me.SupportsMsgType(meDefinition, me.GetCurrentData) { |
| 3364 | return me.NewProcessingError("managed entity does not support Get Current Data Message-Type") |
| 3365 | } |
| 3366 | // Note: G.988 specifies that an error code of (3) should result if more |
| 3367 | // than one attribute is requested |
| 3368 | omci.AttributeMask = binary.BigEndian.Uint16(data[4:6]) |
| 3369 | return nil |
| 3370 | } |
| 3371 | |
| 3372 | func decodeGetCurrentDataRequest(data []byte, p gopacket.PacketBuilder) error { |
| 3373 | omci := &GetCurrentDataRequest{} |
| 3374 | omci.MsgLayerType = LayerTypeGetCurrentDataRequest |
| 3375 | return decodingLayerDecoder(omci, data, p) |
| 3376 | } |
| 3377 | |
| 3378 | // SerializeTo provides serialization of an Get Current Data Request message |
| 3379 | func (omci *GetCurrentDataRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3380 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3381 | err := omci.MeBasePacket.SerializeTo(b) |
| 3382 | if err != nil { |
| 3383 | return err |
| 3384 | } |
| 3385 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3386 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3387 | if omciErr.StatusCode() != me.Success { |
| 3388 | return omciErr.GetError() |
| 3389 | } |
| 3390 | // ME needs to support GetNext |
| 3391 | if !me.SupportsMsgType(meDefinition, me.GetCurrentData) { |
| 3392 | return me.NewProcessingError("managed entity does not support Get Current Data Message-Type") |
| 3393 | } |
| 3394 | bytes, err := b.AppendBytes(2) |
| 3395 | if err != nil { |
| 3396 | return err |
| 3397 | } |
| 3398 | binary.BigEndian.PutUint16(bytes, omci.AttributeMask) |
| 3399 | return nil |
| 3400 | } |
| 3401 | |
| 3402 | ///////////////////////////////////////////////////////////////////////////// |
| 3403 | // |
| 3404 | type GetCurrentDataResponse struct { |
| 3405 | MeBasePacket |
| 3406 | Result me.Results |
| 3407 | AttributeMask uint16 |
| 3408 | Attributes me.AttributeValueMap |
| 3409 | } |
| 3410 | |
| 3411 | func (omci *GetCurrentDataResponse) String() string { |
| 3412 | return fmt.Sprintf("%v, Result: %d (%v), Attribute Mask: %#x, Attributes: %v", |
| 3413 | omci.MeBasePacket.String(), omci.Result, omci.Result, omci.AttributeMask, omci.Attributes) |
| 3414 | } |
| 3415 | |
| 3416 | // DecodeFromBytes decodes the given bytes of a Get Current Data Respnse into this layer |
| 3417 | func (omci *GetCurrentDataResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3418 | // Common ClassID/EntityID decode in msgBase |
| 3419 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 3420 | if err != nil { |
| 3421 | return err |
| 3422 | } |
| 3423 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3424 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3425 | if omciErr.StatusCode() != me.Success { |
| 3426 | return omciErr.GetError() |
| 3427 | } |
| 3428 | // ME needs to support Set |
| 3429 | if !me.SupportsMsgType(meDefinition, me.GetCurrentData) { |
| 3430 | return me.NewProcessingError("managed entity does not support Get Current Data Message-Type") |
| 3431 | } |
| 3432 | omci.AttributeMask = binary.BigEndian.Uint16(data[4:6]) |
| 3433 | |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3434 | switch omci.Result { |
| 3435 | case me.ProcessingError, me.NotSupported, me.UnknownEntity, me.UnknownInstance, me.DeviceBusy: |
| 3436 | return nil // Done (do not try and decode attributes) |
| 3437 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 3438 | // Attribute decode |
| 3439 | omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[6:], p, byte(GetCurrentDataResponseType)) |
| 3440 | if err != nil { |
| 3441 | return err |
| 3442 | } |
| 3443 | return nil |
| 3444 | } |
| 3445 | |
| 3446 | func decodeGetCurrentDataResponse(data []byte, p gopacket.PacketBuilder) error { |
| 3447 | omci := &GetCurrentDataResponse{} |
| 3448 | omci.MsgLayerType = LayerTypeGetCurrentDataResponse |
| 3449 | return decodingLayerDecoder(omci, data, p) |
| 3450 | } |
| 3451 | |
| 3452 | // SerializeTo provides serialization of an Get Current Data Message Type Response |
| 3453 | func (omci *GetCurrentDataResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3454 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3455 | err := omci.MeBasePacket.SerializeTo(b) |
| 3456 | if err != nil { |
| 3457 | return err |
| 3458 | } |
| 3459 | meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass, |
| 3460 | me.ParamData{EntityID: omci.EntityInstance}) |
| 3461 | if omciErr.StatusCode() != me.Success { |
| 3462 | return omciErr.GetError() |
| 3463 | } |
| 3464 | // ME needs to support Get |
| 3465 | if !me.SupportsMsgType(meDefinition, me.GetCurrentData) { |
| 3466 | return me.NewProcessingError("managed entity does not support the Get Current Data Message-Type") |
| 3467 | } |
| 3468 | bytes, err := b.AppendBytes(2) |
| 3469 | if err != nil { |
| 3470 | return err |
| 3471 | } |
| 3472 | binary.BigEndian.PutUint16(bytes[0:2], omci.AttributeMask) |
| 3473 | |
| 3474 | // Attribute serialization |
| 3475 | // TODO: Only Baseline supported at this time |
| 3476 | bytesAvailable := MaxBaselineLength - 9 - 8 |
| 3477 | var failedMask uint16 |
| 3478 | |
| 3479 | err, failedMask = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b, |
| 3480 | byte(GetCurrentDataResponseType), bytesAvailable, opts.FixLengths) |
| 3481 | |
| 3482 | if failedMask != 0 { |
| 3483 | // TODO: See GetResponse serialization above for the steps here |
| 3484 | return me.NewMessageTruncatedError("getCurrentData attribute truncation not yet supported") |
| 3485 | } |
| 3486 | if err != nil { |
| 3487 | return err |
| 3488 | } |
| 3489 | return nil |
| 3490 | } |
| 3491 | |
| 3492 | ///////////////////////////////////////////////////////////////////////////// |
| 3493 | // |
| 3494 | type SetTableRequest struct { |
| 3495 | MeBasePacket |
| 3496 | // TODO: Fix me when extended messages supported) |
| 3497 | } |
| 3498 | |
| 3499 | func (omci *SetTableRequest) String() string { |
| 3500 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 3501 | } |
| 3502 | |
| 3503 | // DecodeFromBytes decodes the given bytes of a Set Table Request into this layer |
| 3504 | func (omci *SetTableRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3505 | // Common ClassID/EntityID decode in msgBase |
| 3506 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 3507 | if err != nil { |
| 3508 | return err |
| 3509 | } |
| 3510 | return errors.New("need to implement") // TODO: Fix me when extended messages supported) |
| 3511 | } |
| 3512 | |
| 3513 | func decodeSetTableRequest(data []byte, p gopacket.PacketBuilder) error { |
| 3514 | omci := &SetTableRequest{} |
| 3515 | omci.MsgLayerType = LayerTypeSetTableRequest |
| 3516 | return decodingLayerDecoder(omci, data, p) |
| 3517 | } |
| 3518 | |
| 3519 | // SerializeTo provides serialization of an Set Table Message Type Request |
| 3520 | func (omci *SetTableRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3521 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3522 | err := omci.MeBasePacket.SerializeTo(b) |
| 3523 | if err != nil { |
| 3524 | return err |
| 3525 | } |
| 3526 | return errors.New("need to implement") /// TODO: Fix me when extended messages supported) |
| 3527 | } |
| 3528 | |
| 3529 | ///////////////////////////////////////////////////////////////////////////// |
| 3530 | // |
| 3531 | type SetTableResponse struct { |
| 3532 | MeBasePacket |
| 3533 | // TODO: Fix me when extended messages supported) |
| 3534 | } |
| 3535 | |
| 3536 | func (omci *SetTableResponse) String() string { |
| 3537 | return fmt.Sprintf("%v", omci.MeBasePacket.String()) |
| 3538 | } |
| 3539 | |
| 3540 | // DecodeFromBytes decodes the given bytes of a Set Table Response into this layer |
| 3541 | func (omci *SetTableResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3542 | // Common ClassID/EntityID decode in msgBase |
| 3543 | err := omci.MeBasePacket.DecodeFromBytes(data, p) |
| 3544 | if err != nil { |
| 3545 | return err |
| 3546 | } |
| 3547 | return errors.New("need to implement") // TODO: Fix me when extended messages supported) |
| 3548 | } |
| 3549 | |
| 3550 | func decodeSetTableResponse(data []byte, p gopacket.PacketBuilder) error { |
| 3551 | omci := &SetTableResponse{} |
| 3552 | omci.MsgLayerType = LayerTypeSetTableResponse |
| 3553 | return decodingLayerDecoder(omci, data, p) |
| 3554 | } |
| 3555 | |
| 3556 | // SerializeTo provides serialization of an Set Table Message Type Response |
| 3557 | func (omci *SetTableResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3558 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3559 | err := omci.MeBasePacket.SerializeTo(b) |
| 3560 | if err != nil { |
| 3561 | return err |
| 3562 | } |
| 3563 | return errors.New("need to implement") // TODO: Fix me when extended messages supported) |
| 3564 | } |
| 3565 | |
| 3566 | ///////////////////////////////////////////////////////////////////////////// |
| 3567 | // |
| 3568 | type UnsupportedMessageTypeResponse struct { |
| 3569 | MeBasePacket |
| 3570 | Result me.Results |
| 3571 | } |
| 3572 | |
| 3573 | // DecodeFromBytes decodes the given bytes of an Unsupported Message Type Response into this layer |
| 3574 | func (omci *UnsupportedMessageTypeResponse) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error { |
| 3575 | return errors.New("you should never really decode this") |
| 3576 | } |
| 3577 | |
| 3578 | // SerializeTo provides serialization of an Unsupported Message Type Response |
| 3579 | func (omci *UnsupportedMessageTypeResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 3580 | // Basic (common) OMCI Header is 8 octets, 10 |
| 3581 | err := omci.MeBasePacket.SerializeTo(b) |
| 3582 | if err != nil { |
| 3583 | return err |
| 3584 | } |
| 3585 | bytes, err := b.AppendBytes(1) |
| 3586 | if err != nil { |
| 3587 | return err |
| 3588 | } |
| 3589 | bytes[0] = byte(omci.Result) |
| 3590 | return nil |
| 3591 | } |