Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 3 | * Copyright 2020-present Open Networking Foundation |
| 4 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 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 |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 8 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 10 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 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. |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 16 | */ |
| 17 | package omci_test |
| 18 | |
| 19 | import ( |
| 20 | "encoding/base64" |
| 21 | "fmt" |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 22 | "github.com/google/gopacket" |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 23 | . "github.com/opencord/omci-lib-go" |
| 24 | me "github.com/opencord/omci-lib-go/generated" |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 25 | "github.com/stretchr/testify/assert" |
| 26 | "strings" |
| 27 | "testing" |
| 28 | ) |
| 29 | |
| 30 | var allMsgTypes = [...]me.MsgType{ |
| 31 | me.Create, |
| 32 | me.Delete, |
| 33 | me.Set, |
| 34 | me.Get, |
| 35 | me.GetAllAlarms, |
| 36 | me.GetAllAlarmsNext, |
| 37 | me.MibUpload, |
| 38 | me.MibUploadNext, |
| 39 | me.MibReset, |
| 40 | me.AlarmNotification, |
| 41 | me.AttributeValueChange, |
| 42 | me.Test, |
| 43 | me.StartSoftwareDownload, |
| 44 | me.DownloadSection, |
| 45 | me.EndSoftwareDownload, |
| 46 | me.ActivateSoftware, |
| 47 | me.CommitSoftware, |
| 48 | me.SynchronizeTime, |
| 49 | me.Reboot, |
| 50 | me.GetNext, |
| 51 | me.TestResult, |
| 52 | me.GetCurrentData, |
| 53 | me.SetTable} |
| 54 | |
| 55 | var allMessageTypes = [...]MessageType{ |
| 56 | CreateRequestType, |
| 57 | CreateResponseType, |
| 58 | DeleteRequestType, |
| 59 | DeleteResponseType, |
| 60 | SetRequestType, |
| 61 | SetResponseType, |
| 62 | GetRequestType, |
| 63 | GetResponseType, |
| 64 | GetAllAlarmsRequestType, |
| 65 | GetAllAlarmsResponseType, |
| 66 | GetAllAlarmsNextRequestType, |
| 67 | GetAllAlarmsNextResponseType, |
| 68 | MibUploadRequestType, |
| 69 | MibUploadResponseType, |
| 70 | MibUploadNextRequestType, |
| 71 | MibUploadNextResponseType, |
| 72 | MibResetRequestType, |
| 73 | MibResetResponseType, |
| 74 | TestRequestType, |
| 75 | TestResponseType, |
| 76 | StartSoftwareDownloadRequestType, |
| 77 | StartSoftwareDownloadResponseType, |
| 78 | DownloadSectionRequestType, |
| 79 | DownloadSectionResponseType, |
| 80 | EndSoftwareDownloadRequestType, |
| 81 | EndSoftwareDownloadResponseType, |
| 82 | ActivateSoftwareRequestType, |
| 83 | ActivateSoftwareResponseType, |
| 84 | CommitSoftwareRequestType, |
| 85 | CommitSoftwareResponseType, |
| 86 | SynchronizeTimeRequestType, |
| 87 | SynchronizeTimeResponseType, |
| 88 | RebootRequestType, |
| 89 | RebootResponseType, |
| 90 | GetNextRequestType, |
| 91 | GetNextResponseType, |
| 92 | GetCurrentDataRequestType, |
| 93 | GetCurrentDataResponseType, |
| 94 | SetTableRequestType, |
| 95 | SetTableResponseType, |
| 96 | // Autonomous ONU messages |
| 97 | AlarmNotificationType, |
| 98 | AttributeValueChangeType, |
| 99 | TestResultType, |
| 100 | } |
| 101 | |
| 102 | var allResults = [...]me.Results{ |
| 103 | me.Success, |
| 104 | me.ProcessingError, |
| 105 | me.NotSupported, |
| 106 | me.ParameterError, |
| 107 | me.UnknownEntity, |
| 108 | me.UnknownInstance, |
| 109 | me.DeviceBusy, |
| 110 | me.InstanceExists} |
| 111 | |
| 112 | // TestMsgTypeStrings tests that base message types can be printed |
| 113 | func TestMsgTypeStrings(t *testing.T) { |
| 114 | for _, msg := range allMsgTypes { |
| 115 | strMsg := msg.String() |
| 116 | assert.NotEqual(t, len(strMsg), 0) |
| 117 | } |
| 118 | unknown := me.MsgType(0xFF) |
| 119 | strMsg := unknown.String() |
| 120 | assert.NotEqual(t, len(strMsg), 0) |
| 121 | } |
| 122 | |
| 123 | // TestMessageTypeStrings tests that request/response/notification |
| 124 | // message types can be printed |
| 125 | func TestMessageTypeStrings(t *testing.T) { |
| 126 | for _, msg := range allMessageTypes { |
| 127 | strMsg := msg.String() |
| 128 | assert.NotEqual(t, len(strMsg), 0) |
| 129 | } |
| 130 | unknown := MessageType(0xFF) |
| 131 | strMsg := unknown.String() |
| 132 | assert.NotEqual(t, len(strMsg), 0) |
| 133 | } |
| 134 | |
| 135 | func TestResultsStrings(t *testing.T) { |
| 136 | for _, code := range allResults { |
| 137 | strMsg := code.String() |
| 138 | assert.NotEqual(t, len(strMsg), 0) |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // TestOmciDecode will test for proper error checking of things that |
| 143 | // are invalid at the OMCI decode layer |
| 144 | func TestOmciDecode(t *testing.T) { |
| 145 | // TID = 0 on autonomous ONU notifications only. Get packet back but ErrorLayer() |
| 146 | // returns non-nil |
| 147 | tidZeroOnNonNotification := "0000440A010C01000400800003010000" + |
| 148 | "00000000000000000000000000000000" + |
| 149 | "000000000000000000000028" |
| 150 | |
| 151 | data, err := stringToPacket(tidZeroOnNonNotification) |
| 152 | assert.NoError(t, err) |
| 153 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 154 | assert.NotNil(t, packet) |
| 155 | assert.NotNil(t, packet.ErrorLayer()) |
| 156 | |
| 157 | // Only Baseline and Extended Message types allowed |
| 158 | invalidMessageType := "000C440F010C01000400800003010000" + |
| 159 | "00000000000000000000000000000000" + |
| 160 | "000000000000000000000028" |
| 161 | |
| 162 | data, err = stringToPacket(invalidMessageType) |
| 163 | assert.NoError(t, err) |
| 164 | packet = gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 165 | assert.NotNil(t, packet) |
| 166 | assert.NotNil(t, packet.ErrorLayer()) |
| 167 | |
| 168 | // Bad baseline message length |
| 169 | badBaselineMsgLength := "000C440A010C01000400800003010000" + |
| 170 | "00000000000000000000000000000000" + |
| 171 | "000000000000000000000029" |
| 172 | |
| 173 | data, err = stringToPacket(badBaselineMsgLength) |
| 174 | assert.NoError(t, err) |
| 175 | packet = gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 176 | assert.NotNil(t, packet) |
| 177 | assert.NotNil(t, packet.ErrorLayer()) |
| 178 | |
| 179 | // Bad extended message length |
| 180 | badExtendedMsgLength := "000C440B010C010000290400800003010000" + |
| 181 | "00000000000000000000000000000000" + |
| 182 | "00000000000000000000" |
| 183 | |
| 184 | data, err = stringToPacket(badExtendedMsgLength) |
| 185 | assert.NoError(t, err) |
| 186 | packet = gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 187 | assert.NotNil(t, packet) |
| 188 | assert.NotNil(t, packet.ErrorLayer()) |
| 189 | |
| 190 | // Huge extended message length |
| 191 | hugeExtendedMsgLength := "000C440B010C010007BD0400800003010000" + |
| 192 | "00000000000000000000000000000000" + |
| 193 | "00000000000000000000" |
| 194 | |
| 195 | data, err = stringToPacket(hugeExtendedMsgLength) |
| 196 | assert.NoError(t, err) |
| 197 | packet = gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 198 | assert.NotNil(t, packet) |
| 199 | assert.NotNil(t, packet.ErrorLayer()) |
| 200 | } |
| 201 | |
| 202 | // TestOmciSerialization will test for proper error checking of things that |
| 203 | // are invalid at the OMCI layer |
| 204 | func TestOmciSerialization(t *testing.T) { |
| 205 | goodMessage := "000C440A010C0100040080000301000000000000000000000000000000000000000000000000000000000028" |
| 206 | |
| 207 | omciLayerDefaults := &OMCI{ |
| 208 | TransactionID: 0x0c, |
| 209 | MessageType: CreateRequestType, |
| 210 | // DeviceIdentifier: BaselineIdent, // Optional, defaults to Baseline |
| 211 | // Length: 0x28, // Optional, defaults to 40 octets |
| 212 | } |
| 213 | omciLayerFixed := &OMCI{ |
| 214 | TransactionID: 0x0c, |
| 215 | MessageType: CreateRequestType, |
| 216 | DeviceIdentifier: BaselineIdent, |
| 217 | Length: 0x28, |
| 218 | } |
| 219 | request := &CreateRequest{ |
| 220 | MeBasePacket: MeBasePacket{ |
| 221 | EntityClass: me.GemPortNetworkCtpClassID, |
| 222 | EntityInstance: uint16(0x100), |
| 223 | }, |
| 224 | Attributes: me.AttributeValueMap{ |
| 225 | "PortId": 0x400, |
| 226 | "TContPointer": 0x8000, |
| 227 | "Direction": 3, |
| 228 | "TrafficManagementPointerForUpstream": 0x100, |
| 229 | "TrafficDescriptorProfilePointerForUpstream": 0, |
| 230 | "PriorityQueuePointerForDownStream": 0, |
| 231 | "TrafficDescriptorProfilePointerForDownstream": 0, |
| 232 | "EncryptionKeyRing": 0, |
| 233 | }, |
| 234 | } |
| 235 | // Test serialization back to former string (using defaults in the message parts) |
| 236 | var options gopacket.SerializeOptions |
| 237 | options.FixLengths = true |
| 238 | |
| 239 | buffer := gopacket.NewSerializeBuffer() |
| 240 | err := gopacket.SerializeLayers(buffer, options, omciLayerDefaults, request) |
| 241 | assert.NoError(t, err) |
| 242 | |
| 243 | outgoingPacket := buffer.Bytes() |
| 244 | reconstituted := packetToString(outgoingPacket) |
| 245 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 246 | |
| 247 | // Test serialization back to former string (using explicit values in the message parts) |
| 248 | buffer = gopacket.NewSerializeBuffer() |
| 249 | err = gopacket.SerializeLayers(buffer, options, omciLayerFixed, request) |
| 250 | assert.NoError(t, err) |
| 251 | |
| 252 | outgoingPacket = buffer.Bytes() |
| 253 | reconstituted = packetToString(outgoingPacket) |
| 254 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 255 | } |
| 256 | |
| 257 | func TestCreateRequestDecode(t *testing.T) { |
| 258 | goodMessage := "000C440A010C01000400800003010000" + |
| 259 | "00000000000000000000000000000000" + |
| 260 | "000000000000000000000028" |
| 261 | data, err := stringToPacket(goodMessage) |
| 262 | assert.NoError(t, err) |
| 263 | |
| 264 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 265 | assert.NotNil(t, packet) |
| 266 | |
| 267 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 268 | assert.NotNil(t, packet) |
| 269 | |
| 270 | omciMsg, ok := omciLayer.(*OMCI) |
| 271 | assert.True(t, ok) |
| 272 | assert.Equal(t, omciMsg.TransactionID, uint16(0xc)) |
| 273 | assert.Equal(t, omciMsg.MessageType, CreateRequestType) |
| 274 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 275 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 276 | |
| 277 | msgLayer := packet.Layer(LayerTypeCreateRequest) |
| 278 | assert.NotNil(t, msgLayer) |
| 279 | |
| 280 | request, ok2 := msgLayer.(*CreateRequest) |
| 281 | assert.True(t, ok2) |
| 282 | assert.Equal(t, request.EntityClass, me.GemPortNetworkCtpClassID) |
| 283 | assert.Equal(t, request.EntityInstance, uint16(0x100)) |
| 284 | |
| 285 | attributes := request.Attributes |
| 286 | assert.NotNil(t, attributes) |
| 287 | |
| 288 | // As this is a create request, gather up all set-by-create attributes |
| 289 | // make sure we got them all, and nothing else |
| 290 | meDefinition, omciErr := me.LoadManagedEntityDefinition(request.EntityClass) |
| 291 | assert.NotNil(t, omciErr) |
| 292 | assert.Equal(t, omciErr.StatusCode(), me.Success) |
| 293 | |
| 294 | attrDefs := meDefinition.GetAttributeDefinitions() |
| 295 | |
| 296 | sbcMask := getSbcMask(meDefinition) |
| 297 | for index := uint(1); index < uint(len(attrDefs)); index++ { |
| 298 | attrName := attrDefs[index].GetName() |
| 299 | |
| 300 | if sbcMask&uint16(1<<(uint)(16-index)) != 0 { |
| 301 | _, ok3 := attributes[attrName] |
| 302 | assert.True(t, ok3) |
| 303 | } else { |
| 304 | _, ok3 := attributes[attrName] |
| 305 | assert.False(t, ok3) |
| 306 | } |
| 307 | //fmt.Printf("Name: %v, Value: %v\n", attrName, attributes[attrName]) |
| 308 | } |
| 309 | // Test serialization back to former string |
| 310 | var options gopacket.SerializeOptions |
| 311 | options.FixLengths = true |
| 312 | |
| 313 | buffer := gopacket.NewSerializeBuffer() |
| 314 | err = gopacket.SerializeLayers(buffer, options, omciMsg, request) |
| 315 | assert.NoError(t, err) |
| 316 | |
| 317 | outgoingPacket := buffer.Bytes() |
| 318 | reconstituted := packetToString(outgoingPacket) |
| 319 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 320 | |
| 321 | // Verify string output for message |
| 322 | packetString := packet.String() |
| 323 | assert.NotZero(t, len(packetString)) |
| 324 | } |
| 325 | |
| 326 | func TestCreateRequestSerialize(t *testing.T) { |
| 327 | goodMessage := "000C440A010C0100040080000301000000000000000000000000000000000000000000000000000000000028" |
| 328 | |
| 329 | omciLayer := &OMCI{ |
| 330 | TransactionID: 0x0c, |
| 331 | MessageType: CreateRequestType, |
| 332 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 333 | // Length: 0x28, // Optional, defaults to 40 octets |
| 334 | } |
| 335 | request := &CreateRequest{ |
| 336 | MeBasePacket: MeBasePacket{ |
| 337 | EntityClass: me.GemPortNetworkCtpClassID, |
| 338 | EntityInstance: uint16(0x100), |
| 339 | }, |
| 340 | Attributes: me.AttributeValueMap{ |
| 341 | "PortId": 0x400, |
| 342 | "TContPointer": 0x8000, |
| 343 | "Direction": 3, |
| 344 | "TrafficManagementPointerForUpstream": 0x100, |
| 345 | "TrafficDescriptorProfilePointerForUpstream": 0, |
| 346 | "PriorityQueuePointerForDownStream": 0, |
| 347 | "TrafficDescriptorProfilePointerForDownstream": 0, |
| 348 | "EncryptionKeyRing": 0, |
| 349 | }, |
| 350 | } |
| 351 | // Test serialization back to former string |
| 352 | var options gopacket.SerializeOptions |
| 353 | options.FixLengths = true |
| 354 | |
| 355 | buffer := gopacket.NewSerializeBuffer() |
| 356 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 357 | assert.NoError(t, err) |
| 358 | |
| 359 | outgoingPacket := buffer.Bytes() |
| 360 | reconstituted := packetToString(outgoingPacket) |
| 361 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 362 | } |
| 363 | |
| 364 | func TestCreateResponseDecode(t *testing.T) { |
| 365 | goodMessage := "0157240a01100001000000000000000000000000000000000000000000000000000000000000000000000028a9ccbeb9" |
| 366 | data, err := stringToPacket(goodMessage) |
| 367 | assert.NoError(t, err) |
| 368 | |
| 369 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 370 | assert.NotNil(t, packet) |
| 371 | |
| 372 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 373 | assert.NotNil(t, packet) |
| 374 | |
| 375 | omciMsg, ok := omciLayer.(*OMCI) |
| 376 | assert.True(t, ok) |
| 377 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0157)) |
| 378 | assert.Equal(t, omciMsg.MessageType, CreateResponseType) |
| 379 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 380 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 381 | |
| 382 | msgLayer := packet.Layer(LayerTypeCreateResponse) |
| 383 | assert.NotNil(t, msgLayer) |
| 384 | |
| 385 | response, ok2 := msgLayer.(*CreateResponse) |
| 386 | assert.True(t, ok2) |
| 387 | assert.NotNil(t, response) |
| 388 | |
| 389 | // Verify string output for message |
| 390 | packetString := packet.String() |
| 391 | assert.NotZero(t, len(packetString)) |
| 392 | } |
| 393 | |
| 394 | func TestCreateResponseSerialize(t *testing.T) { |
| 395 | goodMessage := "0157240a01100001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 396 | |
| 397 | omciLayer := &OMCI{ |
| 398 | TransactionID: 0x0157, |
| 399 | MessageType: CreateResponseType, |
| 400 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 401 | // Length: 0x28, // Optional, defaults to 40 octets |
| 402 | } |
| 403 | request := &CreateResponse{ |
| 404 | MeBasePacket: MeBasePacket{ |
| 405 | EntityClass: me.GalEthernetProfileClassID, |
| 406 | EntityInstance: uint16(1), |
| 407 | }, |
| 408 | Result: me.Success, |
| 409 | AttributeExecutionMask: uint16(0), |
| 410 | } |
| 411 | // Test serialization back to former string |
| 412 | var options gopacket.SerializeOptions |
| 413 | options.FixLengths = true |
| 414 | |
| 415 | buffer := gopacket.NewSerializeBuffer() |
| 416 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 417 | assert.NoError(t, err) |
| 418 | |
| 419 | outgoingPacket := buffer.Bytes() |
| 420 | reconstituted := packetToString(outgoingPacket) |
| 421 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 422 | } |
| 423 | |
| 424 | func TestDeleteRequestDecode(t *testing.T) { |
| 425 | goodMessage := "0211460a00ab0202000000000000000000000000000000000000000000000000000000000000000000000028" |
| 426 | data, err := stringToPacket(goodMessage) |
| 427 | assert.NoError(t, err) |
| 428 | |
| 429 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 430 | assert.NotNil(t, packet) |
| 431 | |
| 432 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 433 | assert.NotNil(t, packet) |
| 434 | |
| 435 | omciMsg, ok := omciLayer.(*OMCI) |
| 436 | assert.True(t, ok) |
| 437 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0211)) |
| 438 | assert.Equal(t, omciMsg.MessageType, DeleteRequestType) |
| 439 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 440 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 441 | |
| 442 | msgLayer := packet.Layer(LayerTypeDeleteRequest) |
| 443 | |
| 444 | assert.NotNil(t, msgLayer) |
| 445 | |
| 446 | request, ok2 := msgLayer.(*DeleteRequest) |
| 447 | assert.True(t, ok2) |
| 448 | assert.NotNil(t, request) |
| 449 | |
| 450 | // Verify string output for message |
| 451 | packetString := packet.String() |
| 452 | assert.NotZero(t, len(packetString)) |
| 453 | } |
| 454 | |
| 455 | func TestDeleteRequestSerialize(t *testing.T) { |
| 456 | goodMessage := "0211460a00ab0202000000000000000000000000000000000000000000000000000000000000000000000028" |
| 457 | |
| 458 | omciLayer := &OMCI{ |
| 459 | TransactionID: 0x0211, |
| 460 | MessageType: DeleteRequestType, |
| 461 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 462 | // Length: 0x28, // Optional, defaults to 40 octets |
| 463 | } |
| 464 | request := &DeleteRequest{ |
| 465 | MeBasePacket: MeBasePacket{ |
| 466 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 467 | EntityInstance: uint16(0x202), |
| 468 | }, |
| 469 | } |
| 470 | // Test serialization back to former string |
| 471 | var options gopacket.SerializeOptions |
| 472 | options.FixLengths = true |
| 473 | |
| 474 | buffer := gopacket.NewSerializeBuffer() |
| 475 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 476 | assert.NoError(t, err) |
| 477 | |
| 478 | outgoingPacket := buffer.Bytes() |
| 479 | reconstituted := packetToString(outgoingPacket) |
| 480 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 481 | } |
| 482 | |
| 483 | func TestDeleteResponseDecode(t *testing.T) { |
| 484 | goodMessage := "0211260a00ab0202000000000000000000000000000000000000000000000000000000000000000000000028013437fb" |
| 485 | data, err := stringToPacket(goodMessage) |
| 486 | assert.NoError(t, err) |
| 487 | |
| 488 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 489 | assert.NotNil(t, packet) |
| 490 | |
| 491 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 492 | assert.NotNil(t, packet) |
| 493 | |
| 494 | omciMsg, ok := omciLayer.(*OMCI) |
| 495 | assert.True(t, ok) |
| 496 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0211)) |
| 497 | assert.Equal(t, omciMsg.MessageType, DeleteResponseType) |
| 498 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 499 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 500 | |
| 501 | msgLayer := packet.Layer(LayerTypeDeleteResponse) |
| 502 | |
| 503 | assert.NotNil(t, msgLayer) |
| 504 | |
| 505 | response, ok2 := msgLayer.(*DeleteResponse) |
| 506 | assert.True(t, ok2) |
| 507 | assert.NotNil(t, response) |
| 508 | |
| 509 | // Verify string output for message |
| 510 | packetString := packet.String() |
| 511 | assert.NotZero(t, len(packetString)) |
| 512 | } |
| 513 | |
| 514 | func TestDeleteResponseSerialize(t *testing.T) { |
| 515 | goodMessage := "0211260a00ab0202000000000000000000000000000000000000000000000000000000000000000000000028" |
| 516 | |
| 517 | omciLayer := &OMCI{ |
| 518 | TransactionID: 0x0211, |
| 519 | MessageType: DeleteResponseType, |
| 520 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 521 | // Length: 0x28, // Optional, defaults to 40 octets |
| 522 | } |
| 523 | request := &DeleteResponse{ |
| 524 | MeBasePacket: MeBasePacket{ |
| 525 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 526 | EntityInstance: uint16(0x202), |
| 527 | }, |
| 528 | Result: me.Success, |
| 529 | } |
| 530 | // Test serialization back to former string |
| 531 | var options gopacket.SerializeOptions |
| 532 | options.FixLengths = true |
| 533 | |
| 534 | buffer := gopacket.NewSerializeBuffer() |
| 535 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 536 | assert.NoError(t, err) |
| 537 | |
| 538 | outgoingPacket := buffer.Bytes() |
| 539 | reconstituted := packetToString(outgoingPacket) |
| 540 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 541 | } |
| 542 | |
| 543 | func TestSetRequestDecode(t *testing.T) { |
| 544 | goodMessage := "0107480a01000000020000000000000000000000000000000000000000000000000000000000000000000028" |
| 545 | data, err := stringToPacket(goodMessage) |
| 546 | assert.NoError(t, err) |
| 547 | |
| 548 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 549 | assert.NotNil(t, packet) |
| 550 | |
| 551 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 552 | assert.NotNil(t, packet) |
| 553 | |
| 554 | omciMsg, ok := omciLayer.(*OMCI) |
| 555 | assert.True(t, ok) |
| 556 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0107)) |
| 557 | assert.Equal(t, omciMsg.MessageType, SetRequestType) |
| 558 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 559 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 560 | |
| 561 | msgLayer := packet.Layer(LayerTypeSetRequest) |
| 562 | assert.NotNil(t, msgLayer) |
| 563 | |
| 564 | request, ok2 := msgLayer.(*SetRequest) |
| 565 | assert.True(t, ok2) |
| 566 | assert.NotNil(t, request) |
| 567 | |
| 568 | // Verify string output for message |
| 569 | packetString := packet.String() |
| 570 | assert.NotZero(t, len(packetString)) |
| 571 | } |
| 572 | |
| 573 | func TestSetRequestSerialize(t *testing.T) { |
| 574 | goodMessage := "0107480a01000000020000000000000000000000000000000000000000000000000000000000000000000028" |
| 575 | |
| 576 | omciLayer := &OMCI{ |
| 577 | TransactionID: 0x0107, |
| 578 | MessageType: SetRequestType, |
| 579 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 580 | // Length: 0x28, // Optional, defaults to 40 octets |
| 581 | } |
| 582 | request := &SetRequest{ |
| 583 | MeBasePacket: MeBasePacket{ |
| 584 | EntityClass: me.OnuGClassID, |
| 585 | EntityInstance: uint16(0), |
| 586 | }, |
| 587 | AttributeMask: uint16(0x200), |
| 588 | Attributes: me.AttributeValueMap{"AdministrativeState": byte(0)}, |
| 589 | } |
| 590 | // Test serialization back to former string |
| 591 | var options gopacket.SerializeOptions |
| 592 | options.FixLengths = true |
| 593 | |
| 594 | buffer := gopacket.NewSerializeBuffer() |
| 595 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 596 | assert.NoError(t, err) |
| 597 | |
| 598 | outgoingPacket := buffer.Bytes() |
| 599 | reconstituted := packetToString(outgoingPacket) |
| 600 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 601 | } |
| 602 | |
| 603 | func TestSetResponseDecode(t *testing.T) { |
| 604 | goodMessage := "0107280a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 605 | data, err := stringToPacket(goodMessage) |
| 606 | assert.NoError(t, err) |
| 607 | |
| 608 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 609 | assert.NotNil(t, packet) |
| 610 | |
| 611 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 612 | assert.NotNil(t, packet) |
| 613 | |
| 614 | omciMsg, ok := omciLayer.(*OMCI) |
| 615 | assert.True(t, ok) |
| 616 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0107)) |
| 617 | assert.Equal(t, omciMsg.MessageType, SetResponseType) |
| 618 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 619 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 620 | |
| 621 | msgLayer := packet.Layer(LayerTypeSetResponse) |
| 622 | assert.NotNil(t, msgLayer) |
| 623 | |
| 624 | response, ok2 := msgLayer.(*SetResponse) |
| 625 | assert.True(t, ok2) |
| 626 | assert.NotNil(t, response) |
| 627 | |
| 628 | // Verify string output for message |
| 629 | packetString := packet.String() |
| 630 | assert.NotZero(t, len(packetString)) |
| 631 | } |
| 632 | |
| 633 | func TestSetResponseSerialize(t *testing.T) { |
| 634 | goodMessage := "0107280a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 635 | |
| 636 | omciLayer := &OMCI{ |
| 637 | TransactionID: 0x0107, |
| 638 | MessageType: SetResponseType, |
| 639 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 640 | // Length: 0x28, // Optional, defaults to 40 octets |
| 641 | } |
| 642 | request := &SetResponse{ |
| 643 | MeBasePacket: MeBasePacket{ |
| 644 | EntityClass: me.OnuGClassID, |
| 645 | EntityInstance: uint16(0), |
| 646 | }, |
| 647 | Result: me.Success, |
| 648 | } |
| 649 | // Test serialization back to former string |
| 650 | var options gopacket.SerializeOptions |
| 651 | options.FixLengths = true |
| 652 | |
| 653 | buffer := gopacket.NewSerializeBuffer() |
| 654 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 655 | assert.NoError(t, err) |
| 656 | |
| 657 | outgoingPacket := buffer.Bytes() |
| 658 | reconstituted := packetToString(outgoingPacket) |
| 659 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 660 | |
| 661 | } |
| 662 | |
| 663 | func TestSetResponseTableFailedAttributesDecode(t *testing.T) { |
| 664 | // This is a SET Response with failed and unsupported attributes |
| 665 | // TODO:Implement |
| 666 | } |
| 667 | |
| 668 | func TestSetResponseTableFailedAttributesSerialize(t *testing.T) { |
| 669 | // This is a SET Response with failed and unsupported attributes |
| 670 | // TODO:Implement |
| 671 | } |
| 672 | |
| 673 | func TestGetRequestDecode(t *testing.T) { |
| 674 | goodMessage := "035e490a01070000004400000000000000000000000000000000000000000000000000000000000000000028" |
| 675 | data, err := stringToPacket(goodMessage) |
| 676 | assert.NoError(t, err) |
| 677 | |
| 678 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 679 | assert.NotNil(t, packet) |
| 680 | |
| 681 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 682 | assert.NotNil(t, packet) |
| 683 | |
| 684 | omciMsg, ok := omciLayer.(*OMCI) |
| 685 | assert.True(t, ok) |
| 686 | assert.Equal(t, omciMsg.TransactionID, uint16(0x035e)) |
| 687 | assert.Equal(t, omciMsg.MessageType, GetRequestType) |
| 688 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 689 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 690 | |
| 691 | msgLayer := packet.Layer(LayerTypeGetRequest) |
| 692 | assert.NotNil(t, msgLayer) |
| 693 | |
| 694 | request, ok2 := msgLayer.(*GetRequest) |
| 695 | assert.True(t, ok2) |
| 696 | assert.NotNil(t, request) |
| 697 | |
| 698 | // Verify string output for message |
| 699 | packetString := packet.String() |
| 700 | assert.NotZero(t, len(packetString)) |
| 701 | } |
| 702 | |
| 703 | func TestGetRequestSerialize(t *testing.T) { |
| 704 | goodMessage := "035e490a01070000004400000000000000000000000000000000000000000000000000000000000000000028" |
| 705 | |
| 706 | omciLayer := &OMCI{ |
| 707 | TransactionID: 0x035e, |
| 708 | MessageType: GetRequestType, |
| 709 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 710 | // Length: 0x28, // Optional, defaults to 40 octets |
| 711 | } |
| 712 | request := &GetRequest{ |
| 713 | MeBasePacket: MeBasePacket{ |
| 714 | EntityClass: me.AniGClassID, |
| 715 | EntityInstance: uint16(0), |
| 716 | }, |
| 717 | AttributeMask: uint16(0x0044), |
| 718 | } |
| 719 | // Test serialization back to former string |
| 720 | var options gopacket.SerializeOptions |
| 721 | options.FixLengths = true |
| 722 | |
| 723 | buffer := gopacket.NewSerializeBuffer() |
| 724 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 725 | assert.NoError(t, err) |
| 726 | |
| 727 | outgoingPacket := buffer.Bytes() |
| 728 | reconstituted := packetToString(outgoingPacket) |
| 729 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 730 | } |
| 731 | |
| 732 | func TestGetResponseDecode(t *testing.T) { |
| 733 | goodMessage := "035e290a01070000000044dbcb05f10000000000000000000000000000000000000000000000000000000028" |
| 734 | data, err := stringToPacket(goodMessage) |
| 735 | assert.NoError(t, err) |
| 736 | |
| 737 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 738 | assert.NotNil(t, packet) |
| 739 | |
| 740 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 741 | assert.NotNil(t, omciLayer) |
| 742 | |
| 743 | omciMsg, ok := omciLayer.(*OMCI) |
| 744 | assert.True(t, ok) |
| 745 | assert.Equal(t, omciMsg.TransactionID, uint16(0x035e)) |
| 746 | assert.Equal(t, omciMsg.MessageType, GetResponseType) |
| 747 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 748 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 749 | |
| 750 | msgLayer := packet.Layer(LayerTypeGetResponse) |
| 751 | assert.NotNil(t, msgLayer) |
| 752 | |
| 753 | response, ok2 := msgLayer.(*GetResponse) |
| 754 | assert.True(t, ok2) |
| 755 | assert.NotNil(t, response) |
| 756 | assert.Equal(t, response.Result, me.Success) |
| 757 | assert.Equal(t, response.AttributeMask, uint16(0x0044)) |
| 758 | assert.Equal(t, response.Attributes["TransmitOpticalLevel"], uint16(0x05f1)) |
| 759 | assert.Equal(t, response.Attributes["OpticalSignalLevel"], uint16(0xdbcb)) |
| 760 | |
| 761 | // Verify string output for message |
| 762 | packetString := packet.String() |
| 763 | assert.NotZero(t, len(packetString)) |
| 764 | } |
| 765 | |
| 766 | func TestGetResponseSerialize(t *testing.T) { |
| 767 | goodMessage := "035e290a01070000000044dbcb05f10000000000000000000000000000000000000000000000000000000028" |
| 768 | |
| 769 | omciLayer := &OMCI{ |
| 770 | TransactionID: 0x035e, |
| 771 | MessageType: GetResponseType, |
| 772 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 773 | // Length: 0x28, // Optional, defaults to 40 octets |
| 774 | } |
| 775 | request := &GetResponse{ |
| 776 | MeBasePacket: MeBasePacket{ |
| 777 | EntityClass: me.AniGClassID, |
| 778 | EntityInstance: uint16(0), |
| 779 | }, |
| 780 | Result: 0, |
| 781 | AttributeMask: uint16(0x0044), |
| 782 | Attributes: me.AttributeValueMap{ |
| 783 | "TransmitOpticalLevel": uint16(0x05f1), |
| 784 | "OpticalSignalLevel": uint16(0xdbcb)}, |
| 785 | } |
| 786 | // Test serialization back to former string |
| 787 | var options gopacket.SerializeOptions |
| 788 | options.FixLengths = true |
| 789 | |
| 790 | buffer := gopacket.NewSerializeBuffer() |
| 791 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 792 | assert.NoError(t, err) |
| 793 | |
| 794 | outgoingPacket := buffer.Bytes() |
| 795 | reconstituted := packetToString(outgoingPacket) |
| 796 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 797 | } |
| 798 | |
| 799 | /////////////////////////////////////////////////////////////////////// |
| 800 | // Packet definitions for attributes of various types/sizes |
| 801 | func toOctets(str string) []byte { |
| 802 | data, err := base64.StdEncoding.DecodeString(str) |
| 803 | if err != nil { |
| 804 | panic(fmt.Sprintf("Invalid Base-64 string: '%v'", str)) |
| 805 | } |
| 806 | return data |
| 807 | } |
| 808 | |
| 809 | func TestGetResponseSerializeTruncationFailure(t *testing.T) { |
| 810 | // Too much data and 'fix-length' is not specified. This response has 26 |
| 811 | // octets in the requested data, but only 25 octets available |
| 812 | |
| 813 | omciLayer := &OMCI{ |
| 814 | TransactionID: 0x035e, |
| 815 | MessageType: GetResponseType, |
| 816 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 817 | // Length: 0x28, // Optional, defaults to 40 octets |
| 818 | } |
| 819 | request := &GetResponse{ |
| 820 | MeBasePacket: MeBasePacket{ |
| 821 | EntityClass: me.OnuGClassID, |
| 822 | EntityInstance: uint16(0), |
| 823 | }, |
| 824 | Result: 0, |
| 825 | AttributeMask: uint16(0xE000), |
| 826 | Attributes: me.AttributeValueMap{ |
| 827 | "VendorId": toOctets("ICAgIA=="), |
| 828 | "Version": toOctets("MAAAAAAAAAAAAAAAAAA="), |
| 829 | "SerialNumber": toOctets("AAAAAAAAAAA="), |
| 830 | }, |
| 831 | } |
| 832 | // Test serialization and verify truncation failure |
| 833 | var options gopacket.SerializeOptions |
| 834 | options.FixLengths = false |
| 835 | |
| 836 | buffer := gopacket.NewSerializeBuffer() |
| 837 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 838 | assert.Error(t, err) |
| 839 | assert.IsType(t, &me.MessageTruncatedError{}, err) |
| 840 | } |
| 841 | |
| 842 | func TestGetResponseSerializeTruncationButOkay(t *testing.T) { |
| 843 | // Too much data and 'fix-length' is specified so it packs as much as |
| 844 | // possible and adjusts the failure masks |
| 845 | |
| 846 | omciLayer := &OMCI{ |
| 847 | TransactionID: 0x035e, |
| 848 | MessageType: GetResponseType, |
| 849 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 850 | // Length: 0x28, // Optional, defaults to 40 octets |
| 851 | } |
| 852 | response := &GetResponse{ |
| 853 | MeBasePacket: MeBasePacket{ |
| 854 | EntityClass: me.OnuGClassID, |
| 855 | EntityInstance: uint16(0), |
| 856 | }, |
| 857 | Result: 0, |
| 858 | AttributeMask: uint16(0xE000), |
| 859 | Attributes: me.AttributeValueMap{ |
| 860 | "VendorId": toOctets("ICAgIA=="), |
| 861 | "Version": toOctets("MAAAAAAAAAAAAAAAAAA="), |
| 862 | "SerialNumber": toOctets("AAAAAAAAAAA="), |
| 863 | }, |
| 864 | } |
| 865 | // Test serialization and verify truncation failure |
| 866 | var options gopacket.SerializeOptions |
| 867 | options.FixLengths = true |
| 868 | |
| 869 | buffer := gopacket.NewSerializeBuffer() |
| 870 | err := gopacket.SerializeLayers(buffer, options, omciLayer, response) |
| 871 | assert.NoError(t, err) |
| 872 | |
| 873 | // Now deserialize it and see if we have the proper result (Attribute Failure) |
| 874 | // and a non-zero failed mask |
| 875 | responsePacket := buffer.Bytes() |
| 876 | packet := gopacket.NewPacket(responsePacket, LayerTypeOMCI, gopacket.NoCopy) |
| 877 | assert.NotNil(t, packet) |
| 878 | |
| 879 | omciLayer2 := packet.Layer(LayerTypeOMCI) |
| 880 | assert.NotNil(t, omciLayer2) |
| 881 | |
| 882 | omciMsg2, ok := omciLayer2.(*OMCI) |
| 883 | assert.True(t, ok) |
| 884 | assert.Equal(t, omciLayer.TransactionID, omciMsg2.TransactionID) |
| 885 | assert.Equal(t, omciLayer.MessageType, GetResponseType) |
| 886 | assert.Equal(t, omciLayer.DeviceIdentifier, BaselineIdent) |
| 887 | assert.Equal(t, omciLayer.Length, uint16(40)) |
| 888 | |
| 889 | msgLayer2 := packet.Layer(LayerTypeGetResponse) |
| 890 | assert.NotNil(t, msgLayer2) |
| 891 | |
| 892 | response2, ok2 := msgLayer2.(*GetResponse) |
| 893 | assert.True(t, ok2) |
| 894 | assert.Equal(t, me.AttributeFailure, response2.Result) |
| 895 | assert.NotZero(t, response2.AttributeMask) |
| 896 | assert.NotZero(t, response2.FailedAttributeMask) |
| 897 | assert.Zero(t, response2.UnsupportedAttributeMask) |
| 898 | } |
| 899 | |
| 900 | func TestGetResponseTableFailedAttributesDecode(t *testing.T) { |
| 901 | // This is a GET Response with failed and unsupported attributes |
| 902 | // TODO:Implement |
| 903 | } |
| 904 | |
| 905 | func TestGetResponseTableFailedAttributesSerialize(t *testing.T) { |
| 906 | // This is a GET Response with failed and unsupported attributes |
| 907 | // TODO:Implement |
| 908 | } |
| 909 | |
| 910 | func TestGetResponseTableAttributeDecode(t *testing.T) { |
| 911 | // This is a GET Response for a table attribute. It should return the attribute |
| 912 | // size as a uint16. |
| 913 | // TODO:Implement |
| 914 | } |
| 915 | |
| 916 | func TestGetResponseTableAttributeSerialize(t *testing.T) { |
| 917 | // This is a GET Response for a table attribute. It should return the attribute |
| 918 | // size as a uint16. |
| 919 | // TODO:Implement |
| 920 | } |
| 921 | |
| 922 | func TestGetAllAlarmsRequestDecode(t *testing.T) { |
| 923 | goodMessage := "04454b0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 924 | data, err := stringToPacket(goodMessage) |
| 925 | assert.NoError(t, err) |
| 926 | |
| 927 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 928 | assert.NotNil(t, packet) |
| 929 | |
| 930 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 931 | assert.NotNil(t, packet) |
| 932 | |
| 933 | omciMsg, ok := omciLayer.(*OMCI) |
| 934 | assert.True(t, ok) |
| 935 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0445)) |
| 936 | assert.Equal(t, omciMsg.MessageType, GetAllAlarmsRequestType) |
| 937 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 938 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 939 | |
| 940 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsRequest) |
| 941 | assert.NotNil(t, msgLayer) |
| 942 | |
| 943 | request, ok2 := msgLayer.(*GetAllAlarmsRequest) |
| 944 | assert.True(t, ok2) |
| 945 | assert.NotNil(t, request) |
| 946 | assert.Equal(t, request.AlarmRetrievalMode, byte(0)) |
| 947 | |
| 948 | // Verify string output for message |
| 949 | packetString := packet.String() |
| 950 | assert.NotZero(t, len(packetString)) |
| 951 | } |
| 952 | |
| 953 | func TestGetAllAlarmsRequestSerialize(t *testing.T) { |
| 954 | goodMessage := "04454b0a00020000010000000000000000000000000000000000000000000000000000000000000000000028" |
| 955 | |
| 956 | omciLayer := &OMCI{ |
| 957 | TransactionID: 0x0445, |
| 958 | MessageType: GetAllAlarmsRequestType, |
| 959 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 960 | // Length: 0x28, // Optional, defaults to 40 octets |
| 961 | } |
| 962 | request := &GetAllAlarmsRequest{ |
| 963 | MeBasePacket: MeBasePacket{ |
| 964 | EntityClass: me.OnuDataClassID, |
| 965 | EntityInstance: uint16(0), |
| 966 | }, |
| 967 | AlarmRetrievalMode: byte(1), |
| 968 | } |
| 969 | // Test serialization back to former string |
| 970 | var options gopacket.SerializeOptions |
| 971 | options.FixLengths = true |
| 972 | |
| 973 | buffer := gopacket.NewSerializeBuffer() |
| 974 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 975 | assert.NoError(t, err) |
| 976 | |
| 977 | outgoingPacket := buffer.Bytes() |
| 978 | reconstituted := packetToString(outgoingPacket) |
| 979 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 980 | } |
| 981 | |
| 982 | func TestGetAllAlarmsResponseDecode(t *testing.T) { |
| 983 | goodMessage := "04452b0a00020000000300000000000000000000000000000000000000000000000000000000000000000028" |
| 984 | data, err := stringToPacket(goodMessage) |
| 985 | assert.NoError(t, err) |
| 986 | |
| 987 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 988 | assert.NotNil(t, packet) |
| 989 | |
| 990 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 991 | assert.NotNil(t, packet) |
| 992 | |
| 993 | omciMsg, ok := omciLayer.(*OMCI) |
| 994 | assert.True(t, ok) |
| 995 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0445)) |
| 996 | assert.Equal(t, omciMsg.MessageType, GetAllAlarmsResponseType) |
| 997 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 998 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 999 | |
| 1000 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsResponse) |
| 1001 | assert.NotNil(t, msgLayer) |
| 1002 | |
| 1003 | response, ok2 := msgLayer.(*GetAllAlarmsResponse) |
| 1004 | assert.True(t, ok2) |
| 1005 | assert.NotNil(t, response) |
| 1006 | assert.Equal(t, response.NumberOfCommands, uint16(3)) |
| 1007 | |
| 1008 | // Verify string output for message |
| 1009 | packetString := packet.String() |
| 1010 | assert.NotZero(t, len(packetString)) |
| 1011 | } |
| 1012 | |
| 1013 | func TestGetAllAlarmsResponseSerialize(t *testing.T) { |
| 1014 | goodMessage := "04452b0a00020000000300000000000000000000000000000000000000000000000000000000000000000028" |
| 1015 | |
| 1016 | omciLayer := &OMCI{ |
| 1017 | TransactionID: 0x0445, |
| 1018 | MessageType: GetAllAlarmsResponseType, |
| 1019 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1020 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1021 | } |
| 1022 | request := &GetAllAlarmsResponse{ |
| 1023 | MeBasePacket: MeBasePacket{ |
| 1024 | EntityClass: me.OnuDataClassID, |
| 1025 | EntityInstance: uint16(0), |
| 1026 | }, |
| 1027 | NumberOfCommands: uint16(3), |
| 1028 | } |
| 1029 | // Test serialization back to former string |
| 1030 | var options gopacket.SerializeOptions |
| 1031 | options.FixLengths = true |
| 1032 | |
| 1033 | buffer := gopacket.NewSerializeBuffer() |
| 1034 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1035 | assert.NoError(t, err) |
| 1036 | |
| 1037 | outgoingPacket := buffer.Bytes() |
| 1038 | reconstituted := packetToString(outgoingPacket) |
| 1039 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1040 | } |
| 1041 | |
| 1042 | func TestGetAllAlarmsNextRequestDecode(t *testing.T) { |
| 1043 | goodMessage := "02344c0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1044 | |
| 1045 | data, err := stringToPacket(goodMessage) |
| 1046 | assert.NoError(t, err) |
| 1047 | |
| 1048 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1049 | assert.NotNil(t, packet) |
| 1050 | |
| 1051 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1052 | assert.NotNil(t, packet) |
| 1053 | |
| 1054 | omciMsg, ok := omciLayer.(*OMCI) |
| 1055 | assert.True(t, ok) |
| 1056 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0234)) |
| 1057 | assert.Equal(t, omciMsg.MessageType, GetAllAlarmsNextRequestType) |
| 1058 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1059 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1060 | |
| 1061 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextRequest) |
| 1062 | assert.NotNil(t, msgLayer) |
| 1063 | |
| 1064 | request, ok2 := msgLayer.(*GetAllAlarmsNextRequest) |
| 1065 | assert.True(t, ok2) |
| 1066 | assert.NotNil(t, request) |
| 1067 | |
| 1068 | // Verify string output for message |
| 1069 | packetString := packet.String() |
| 1070 | assert.NotZero(t, len(packetString)) |
| 1071 | } |
| 1072 | |
| 1073 | func TestGetAllAlarmsNextRequestSerialize(t *testing.T) { |
| 1074 | goodMessage := "02344c0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1075 | |
| 1076 | omciLayer := &OMCI{ |
| 1077 | TransactionID: 0x0234, |
| 1078 | MessageType: GetAllAlarmsNextRequestType, |
| 1079 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1080 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1081 | } |
| 1082 | request := &GetAllAlarmsNextRequest{ |
| 1083 | MeBasePacket: MeBasePacket{ |
| 1084 | EntityClass: me.OnuDataClassID, |
| 1085 | EntityInstance: uint16(0), |
| 1086 | }, |
| 1087 | CommandSequenceNumber: uint16(0), |
| 1088 | } |
| 1089 | // Test serialization back to former string |
| 1090 | var options gopacket.SerializeOptions |
| 1091 | options.FixLengths = true |
| 1092 | |
| 1093 | buffer := gopacket.NewSerializeBuffer() |
| 1094 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1095 | assert.NoError(t, err) |
| 1096 | |
| 1097 | outgoingPacket := buffer.Bytes() |
| 1098 | reconstituted := packetToString(outgoingPacket) |
| 1099 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1100 | } |
| 1101 | |
| 1102 | func TestGetAllAlarmsNextResponseDecode(t *testing.T) { |
| 1103 | goodMessage := "02342c0a00020000000b01028000000000000000000000000000000000000000000000000000000000000028f040fc87" |
| 1104 | data, err := stringToPacket(goodMessage) |
| 1105 | assert.NoError(t, err) |
| 1106 | |
| 1107 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1108 | assert.NotNil(t, packet) |
| 1109 | |
| 1110 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1111 | assert.NotNil(t, packet) |
| 1112 | |
| 1113 | omciMsg, ok := omciLayer.(*OMCI) |
| 1114 | assert.True(t, ok) |
| 1115 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0234)) |
| 1116 | assert.Equal(t, omciMsg.MessageType, GetAllAlarmsNextResponseType) |
| 1117 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1118 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1119 | |
| 1120 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextResponse) |
| 1121 | assert.NotNil(t, msgLayer) |
| 1122 | |
| 1123 | response, ok2 := msgLayer.(*GetAllAlarmsNextResponse) |
| 1124 | assert.True(t, ok2) |
| 1125 | assert.NotNil(t, response) |
| 1126 | |
| 1127 | var alarms [224 / 8]byte |
| 1128 | alarms[0] = 0x80 |
| 1129 | assert.Equal(t, response.AlarmEntityClass, me.PhysicalPathTerminationPointEthernetUniClassID) |
| 1130 | assert.Equal(t, response.AlarmEntityInstance, uint16(0x102)) |
| 1131 | assert.Equal(t, response.AlarmBitMap, alarms) |
| 1132 | |
| 1133 | // Verify string output for message |
| 1134 | packetString := packet.String() |
| 1135 | assert.NotZero(t, len(packetString)) |
| 1136 | } |
| 1137 | |
| 1138 | func TestGetAllAlarmsNextResponseSerialize(t *testing.T) { |
| 1139 | goodMessage := "02342c0a00020000000b01028000000000000000000000000000000000000000000000000000000000000028" |
| 1140 | |
| 1141 | omciLayer := &OMCI{ |
| 1142 | TransactionID: 0x0234, |
| 1143 | MessageType: GetAllAlarmsNextResponseType, |
| 1144 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1145 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1146 | } |
| 1147 | var alarms [224 / 8]byte |
| 1148 | alarms[0] = 0x80 |
| 1149 | |
| 1150 | request := &GetAllAlarmsNextResponse{ |
| 1151 | MeBasePacket: MeBasePacket{ |
| 1152 | EntityClass: me.OnuDataClassID, |
| 1153 | EntityInstance: uint16(0), |
| 1154 | }, |
| 1155 | AlarmEntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 1156 | AlarmEntityInstance: uint16(0x102), |
| 1157 | AlarmBitMap: alarms, |
| 1158 | } |
| 1159 | // Test serialization back to former string |
| 1160 | var options gopacket.SerializeOptions |
| 1161 | options.FixLengths = true |
| 1162 | |
| 1163 | buffer := gopacket.NewSerializeBuffer() |
| 1164 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1165 | assert.NoError(t, err) |
| 1166 | |
| 1167 | outgoingPacket := buffer.Bytes() |
| 1168 | reconstituted := packetToString(outgoingPacket) |
| 1169 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1170 | } |
| 1171 | |
| 1172 | func TestGetAllAlarmsNextResponseBadCommandNumberDecode(t *testing.T) { |
| 1173 | // Test of a GetNext Response that results when an invalid command number |
| 1174 | // is requested. In the case where the ONU receives a get all alarms next |
| 1175 | // request message in which the command sequence number is out of range, |
| 1176 | // the ONU should respond with a message in which bytes 9 to 40 are all |
| 1177 | // set to 0. This corresponds to a response with entity class 0, entity |
| 1178 | // instance 0, and bit map all 0s. |
| 1179 | //TODO: Implement |
| 1180 | } |
| 1181 | |
| 1182 | func TestGetAllAlarmsNextResponseBadCommandNumberSerialize(t *testing.T) { |
| 1183 | // Test of a GetNext Response that results when an invalid command number |
| 1184 | // is requested. |
| 1185 | //TODO: Implement |
| 1186 | } |
| 1187 | |
| 1188 | func TestMibUploadRequestDecode(t *testing.T) { |
| 1189 | goodMessage := "03604d0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1190 | data, err := stringToPacket(goodMessage) |
| 1191 | assert.NoError(t, err) |
| 1192 | |
| 1193 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1194 | assert.NotNil(t, packet) |
| 1195 | |
| 1196 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1197 | assert.NotNil(t, packet) |
| 1198 | |
| 1199 | omciMsg, ok := omciLayer.(*OMCI) |
| 1200 | assert.True(t, ok) |
| 1201 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0360)) |
| 1202 | assert.Equal(t, omciMsg.MessageType, MibUploadRequestType) |
| 1203 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1204 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1205 | msgLayer := packet.Layer(LayerTypeMibUploadRequest) |
| 1206 | |
| 1207 | assert.NotNil(t, msgLayer) |
| 1208 | |
| 1209 | request, ok2 := msgLayer.(*MibUploadRequest) |
| 1210 | assert.True(t, ok2) |
| 1211 | assert.NotNil(t, request) |
| 1212 | |
| 1213 | // Verify string output for message |
| 1214 | packetString := packet.String() |
| 1215 | assert.NotZero(t, len(packetString)) |
| 1216 | } |
| 1217 | |
| 1218 | func TestMibUploadRequestSerialize(t *testing.T) { |
| 1219 | goodMessage := "03604d0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1220 | |
| 1221 | omciLayer := &OMCI{ |
| 1222 | TransactionID: 0x0360, |
| 1223 | MessageType: MibUploadRequestType, |
| 1224 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1225 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1226 | } |
| 1227 | var alarms [224 / 8]byte |
| 1228 | alarms[0] = 0x80 |
| 1229 | |
| 1230 | request := &MibUploadRequest{ |
| 1231 | MeBasePacket: MeBasePacket{ |
| 1232 | EntityClass: me.OnuDataClassID, |
| 1233 | EntityInstance: uint16(0), |
| 1234 | }, |
| 1235 | } |
| 1236 | // Test serialization back to former string |
| 1237 | var options gopacket.SerializeOptions |
| 1238 | options.FixLengths = true |
| 1239 | |
| 1240 | buffer := gopacket.NewSerializeBuffer() |
| 1241 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1242 | assert.NoError(t, err) |
| 1243 | |
| 1244 | outgoingPacket := buffer.Bytes() |
| 1245 | reconstituted := packetToString(outgoingPacket) |
| 1246 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1247 | } |
| 1248 | |
| 1249 | func TestMibUploadResponse(t *testing.T) { |
| 1250 | goodMessage := "03602d0a00020000011200000000000000000000000000000000000000000000000000000000000000000028" |
| 1251 | data, err := stringToPacket(goodMessage) |
| 1252 | assert.NoError(t, err) |
| 1253 | |
| 1254 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1255 | assert.NotNil(t, packet) |
| 1256 | |
| 1257 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1258 | assert.NotNil(t, packet) |
| 1259 | |
| 1260 | omciMsg, ok := omciLayer.(*OMCI) |
| 1261 | assert.True(t, ok) |
| 1262 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0360)) |
| 1263 | assert.Equal(t, omciMsg.MessageType, MibUploadResponseType) |
| 1264 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1265 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1266 | |
| 1267 | msgLayer := packet.Layer(LayerTypeMibUploadResponse) |
| 1268 | assert.NotNil(t, msgLayer) |
| 1269 | |
| 1270 | response, ok2 := msgLayer.(*MibUploadResponse) |
| 1271 | assert.True(t, ok2) |
| 1272 | assert.NotNil(t, response) |
| 1273 | assert.Equal(t, response.NumberOfCommands, uint16(0x112)) |
| 1274 | } |
| 1275 | |
| 1276 | func TestMibUploadResponseSerialize(t *testing.T) { |
| 1277 | goodMessage := "03602d0a00020000011200000000000000000000000000000000000000000000000000000000000000000028" |
| 1278 | |
| 1279 | omciLayer := &OMCI{ |
| 1280 | TransactionID: 0x0360, |
| 1281 | MessageType: MibUploadResponseType, |
| 1282 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1283 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1284 | } |
| 1285 | var alarms [224 / 8]byte |
| 1286 | alarms[0] = 0x80 |
| 1287 | |
| 1288 | request := &MibUploadResponse{ |
| 1289 | MeBasePacket: MeBasePacket{ |
| 1290 | EntityClass: me.OnuDataClassID, |
| 1291 | EntityInstance: uint16(0), |
| 1292 | }, |
| 1293 | NumberOfCommands: uint16(0x112), |
| 1294 | } |
| 1295 | // Test serialization back to former string |
| 1296 | var options gopacket.SerializeOptions |
| 1297 | options.FixLengths = true |
| 1298 | |
| 1299 | buffer := gopacket.NewSerializeBuffer() |
| 1300 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1301 | assert.NoError(t, err) |
| 1302 | |
| 1303 | outgoingPacket := buffer.Bytes() |
| 1304 | reconstituted := packetToString(outgoingPacket) |
| 1305 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1306 | } |
| 1307 | |
| 1308 | func TestMibUploadNextRequestDecode(t *testing.T) { |
| 1309 | goodMessage := "02864e0a00020000003a00000000000000000000000000000000000000000000000000000000000000000028" |
| 1310 | data, err := stringToPacket(goodMessage) |
| 1311 | assert.NoError(t, err) |
| 1312 | |
| 1313 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1314 | assert.NotNil(t, packet) |
| 1315 | |
| 1316 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1317 | assert.NotNil(t, packet) |
| 1318 | |
| 1319 | omciMsg, ok := omciLayer.(*OMCI) |
| 1320 | assert.True(t, ok) |
| 1321 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0286)) |
| 1322 | assert.Equal(t, omciMsg.MessageType, MibUploadNextRequestType) |
| 1323 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1324 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1325 | |
| 1326 | msgLayer := packet.Layer(LayerTypeMibUploadNextRequest) |
| 1327 | assert.NotNil(t, msgLayer) |
| 1328 | |
| 1329 | request, ok2 := msgLayer.(*MibUploadNextRequest) |
| 1330 | assert.True(t, ok2) |
| 1331 | assert.NotNil(t, request) |
| 1332 | assert.Equal(t, request.CommandSequenceNumber, uint16(0x3a)) |
| 1333 | |
| 1334 | // Verify string output for message |
| 1335 | packetString := packet.String() |
| 1336 | assert.NotZero(t, len(packetString)) |
| 1337 | } |
| 1338 | |
| 1339 | func TestMibUploadNextRequestSerialize(t *testing.T) { |
| 1340 | goodMessage := "02864e0a00020000003a00000000000000000000000000000000000000000000000000000000000000000028" |
| 1341 | |
| 1342 | omciLayer := &OMCI{ |
| 1343 | TransactionID: 0x0286, |
| 1344 | MessageType: MibUploadNextRequestType, |
| 1345 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1346 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1347 | } |
| 1348 | request := &MibUploadNextRequest{ |
| 1349 | MeBasePacket: MeBasePacket{ |
| 1350 | EntityClass: me.OnuDataClassID, |
| 1351 | EntityInstance: uint16(0), |
| 1352 | }, |
| 1353 | CommandSequenceNumber: uint16(0x3a), |
| 1354 | } |
| 1355 | // Test serialization back to former string |
| 1356 | var options gopacket.SerializeOptions |
| 1357 | options.FixLengths = true |
| 1358 | |
| 1359 | buffer := gopacket.NewSerializeBuffer() |
| 1360 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1361 | assert.NoError(t, err) |
| 1362 | |
| 1363 | outgoingPacket := buffer.Bytes() |
| 1364 | reconstituted := packetToString(outgoingPacket) |
| 1365 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1366 | } |
| 1367 | |
| 1368 | func TestMibUploadNextResponseDecode(t *testing.T) { |
| 1369 | goodMessage := "02862e0a0002000001150000fff0000000000000000000010100000000010000000000000000000000000028" |
| 1370 | data, err := stringToPacket(goodMessage) |
| 1371 | assert.NoError(t, err) |
| 1372 | |
| 1373 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1374 | assert.NotNil(t, packet) |
| 1375 | |
| 1376 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1377 | assert.NotNil(t, packet) |
| 1378 | |
| 1379 | omciMsg, ok := omciLayer.(*OMCI) |
| 1380 | assert.True(t, ok) |
| 1381 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0286)) |
| 1382 | assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType) |
| 1383 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1384 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1385 | |
| 1386 | msgLayer := packet.Layer(LayerTypeMibUploadNextResponse) |
| 1387 | assert.NotNil(t, msgLayer) |
| 1388 | |
| 1389 | response, ok2 := msgLayer.(*MibUploadNextResponse) |
| 1390 | assert.True(t, ok2) |
| 1391 | assert.NotNil(t, response) |
| 1392 | assert.Equal(t, response.ReportedME.GetClassID(), me.PriorityQueueClassID) |
| 1393 | assert.Equal(t, response.ReportedME.GetEntityID(), uint16(0)) |
| 1394 | |
| 1395 | attributes := me.AttributeValueMap{ |
| 1396 | "QueueConfigurationOption": byte(0), |
| 1397 | "MaximumQueueSize": uint16(0), |
| 1398 | "AllocatedQueueSize": uint16(0), |
| 1399 | "DiscardBlockCounterResetInterval": uint16(0), |
| 1400 | "ThresholdValueForDiscardedBlocksDueToBufferOverflow": uint16(0), |
| 1401 | "RelatedPort": uint32(16842752), |
| 1402 | "TrafficSchedulerPointer": uint16(0), |
| 1403 | "Weight": byte(1), |
| 1404 | "BackPressureOperation": uint16(0), |
| 1405 | "BackPressureTime": uint32(0), |
| 1406 | "BackPressureOccurQueueThreshold": uint16(0), |
| 1407 | "BackPressureClearQueueThreshold": uint16(0), |
| 1408 | } |
| 1409 | for name, value := range attributes { |
| 1410 | pktValue, err := response.ReportedME.GetAttribute(name) |
| 1411 | assert.Nil(t, err) |
| 1412 | assert.Equal(t, pktValue, value) |
| 1413 | } |
| 1414 | // Verify string output for message |
| 1415 | packetString := packet.String() |
| 1416 | assert.NotZero(t, len(packetString)) |
| 1417 | } |
| 1418 | |
| 1419 | func TestMibUploadNextResponseSerialize(t *testing.T) { |
| 1420 | goodMessage := "02862e0a0002000001150000fff0000000000000000000010100000000010000000000000000000000000028" |
| 1421 | |
| 1422 | omciLayer := &OMCI{ |
| 1423 | TransactionID: 0x0286, |
| 1424 | MessageType: MibUploadNextResponseType, |
| 1425 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1426 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1427 | } |
| 1428 | paramData := me.ParamData{ |
| 1429 | EntityID: uint16(0), |
| 1430 | Attributes: me.AttributeValueMap{ |
| 1431 | "QueueConfigurationOption": byte(0), |
| 1432 | "MaximumQueueSize": uint16(0), |
| 1433 | "AllocatedQueueSize": uint16(0), |
| 1434 | "DiscardBlockCounterResetInterval": uint16(0), |
| 1435 | "ThresholdValueForDiscardedBlocksDueToBufferOverflow": uint16(0), |
| 1436 | "RelatedPort": uint32(16842752), |
| 1437 | "TrafficSchedulerPointer": uint16(0), |
| 1438 | "Weight": byte(1), |
| 1439 | "BackPressureOperation": uint16(0), |
| 1440 | "BackPressureTime": uint32(0), |
| 1441 | "BackPressureOccurQueueThreshold": uint16(0), |
| 1442 | "BackPressureClearQueueThreshold": uint16(0), |
| 1443 | }, |
| 1444 | } |
| 1445 | reportedME, err := me.NewPriorityQueue(paramData) |
| 1446 | assert.NotNil(t, err) |
| 1447 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1448 | |
| 1449 | request := &MibUploadNextResponse{ |
| 1450 | MeBasePacket: MeBasePacket{ |
| 1451 | EntityClass: me.OnuDataClassID, |
| 1452 | EntityInstance: uint16(0), |
| 1453 | }, |
| 1454 | ReportedME: *reportedME, |
| 1455 | } |
| 1456 | // Test serialization back to former string |
| 1457 | var options gopacket.SerializeOptions |
| 1458 | options.FixLengths = true |
| 1459 | |
| 1460 | buffer := gopacket.NewSerializeBuffer() |
| 1461 | omciErr := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1462 | assert.NoError(t, omciErr) |
| 1463 | |
| 1464 | outgoingPacket := buffer.Bytes() |
| 1465 | reconstituted := packetToString(outgoingPacket) |
| 1466 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1467 | } |
| 1468 | |
| 1469 | func TestMibUploadNextResponseBadCommandNumberDecode(t *testing.T) { |
| 1470 | // Test of a MIB Upload next Response that results when an invalid command number. |
| 1471 | // Note that if all attributes of a managed entity do not fit within one MIB |
| 1472 | // upload next response message, the attributes will be split over several |
| 1473 | // messages. The OLT can use the information in the attribute mask to determine |
| 1474 | // which attribute values are reported in which MIB upload next response message. |
| 1475 | //TODO: Implement |
| 1476 | } |
| 1477 | |
| 1478 | func TestMibUploadNextResponseBadCommandNumberSerialize(t *testing.T) { |
| 1479 | // Test of a MIB Upload next Response that results when an invalid command number |
| 1480 | // is requested. |
| 1481 | //TODO: Implement |
| 1482 | } |
| 1483 | |
| 1484 | // TODO: Create request/response tests for all of the following types |
| 1485 | //Test, |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1486 | // 1 2 3 4 |
| 1487 | // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 |
| 1488 | // 0004530a00070001ff000f424001000100000000000000000000000000000000000000000000000000000028 |
| 1489 | // 0004530a |
| 1490 | // 00070001 - ONU-G instance 0001 |
| 1491 | // ff - window size - 1 |
| 1492 | // 000f4240 - image size |
| 1493 | // 01 |
| 1494 | // 000100000000000000000000000000000000000000000000000000000028 |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1495 | func TestStartSoftwareDownloadRequestDecode(t *testing.T) { |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1496 | goodMessage := "0004530a00070001ff000f424001000100000000000000000000000000000000000000000000000000000028" |
| 1497 | data, err := stringToPacket(goodMessage) |
| 1498 | assert.NoError(t, err) |
| 1499 | |
| 1500 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1501 | assert.NotNil(t, packet) |
| 1502 | |
| 1503 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1504 | assert.NotNil(t, packet) |
| 1505 | |
| 1506 | omciMsg, ok := omciLayer.(*OMCI) |
| 1507 | assert.True(t, ok) |
| 1508 | assert.Equal(t, uint16(0x0004), omciMsg.TransactionID) |
| 1509 | assert.Equal(t, StartSoftwareDownloadRequestType, omciMsg.MessageType) |
| 1510 | assert.True(t, omciMsg.ResponseExpected) |
| 1511 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1512 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1513 | |
| 1514 | msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest) |
| 1515 | assert.NotNil(t, msgLayer) |
| 1516 | |
| 1517 | request, ok2 := msgLayer.(*StartSoftwareDownloadRequest) |
| 1518 | assert.True(t, ok2) |
| 1519 | assert.NotNil(t, request) |
| 1520 | assert.Equal(t, uint8(0xff), request.WindowSize) |
| 1521 | assert.Equal(t, uint32(0x000f4240), request.ImageSize) |
| 1522 | |
| 1523 | // Verify string output for message |
| 1524 | packetString := packet.String() |
| 1525 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | func TestStartSoftwareDownloadRequestSerialize(t *testing.T) { |
| 1529 | //// TODO: Need to complete implementation & debug this |
| 1530 | //goodMessage := "0000530a0007000113000f424001000100000000000000000000000000000000000000000000000000000028" |
| 1531 | // |
| 1532 | //omciLayer := &OMCI{ |
| 1533 | // TransactionID: 0x01, |
| 1534 | // MessageType: StartSoftwareDownloadRequestType, |
| 1535 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1536 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1537 | //} |
| 1538 | //request := &StartSoftwareDownloadRequest{ |
| 1539 | // MeBasePacket: MeBasePacket{ |
| 1540 | // EntityClass: OnuDataClassID, |
| 1541 | // // Default Instance ID is 0 |
| 1542 | // }, |
| 1543 | //} |
| 1544 | //// Test serialization back to former string |
| 1545 | //var options gopacket.SerializeOptions |
| 1546 | //options.FixLengths = true |
| 1547 | // |
| 1548 | //buffer := gopacket.NewSerializeBuffer() |
| 1549 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1550 | //assert.NoError(t, err) |
| 1551 | // |
| 1552 | //outgoingPacket := buffer.Bytes() |
| 1553 | //reconstituted := packetToString(outgoingPacket) |
| 1554 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1555 | } |
| 1556 | |
| 1557 | func TestStartSoftwareDownloadResponseDecode(t *testing.T) { |
| 1558 | // TODO: Need to complete implementation & debug this |
| 1559 | //goodMessage := "" |
| 1560 | //data, err := stringToPacket(goodMessage) |
| 1561 | //assert.NoError(t, err) |
| 1562 | // |
| 1563 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1564 | //assert.NotNil(t, packet) |
| 1565 | // |
| 1566 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1567 | //assert.NotNil(t, packet) |
| 1568 | // |
| 1569 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1570 | //assert.True(t, ok) |
| 1571 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1572 | //assert.Equal(t, omciMsg.MessageType, StartSoftwareDownloadResponseType) |
| 1573 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1574 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1575 | // |
| 1576 | //msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadResponse) |
| 1577 | // |
| 1578 | //assert.NotNil(t, msgLayer) |
| 1579 | // |
| 1580 | //response, ok2 := msgLayer.(*StartSoftwareDownloadResponse) |
| 1581 | //assert.True(t, ok2) |
| 1582 | //assert.NotNil(t, response) |
| 1583 | // |
| 1584 | //// Verify string output for message |
| 1585 | //packetString := packet.String() |
| 1586 | //assert.NotZero(t, len(packetString)) |
| 1587 | } |
| 1588 | |
| 1589 | func TestStartSoftwareDownloadResponseSerialize(t *testing.T) { |
| 1590 | // TODO: Need to complete implementation & debug this |
| 1591 | //goodMessage := "" |
| 1592 | // |
| 1593 | //omciLayer := &OMCI{ |
| 1594 | // TransactionID: 0x01, |
| 1595 | // MessageType: StartSoftwareDownloadResponseType, |
| 1596 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1597 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1598 | //} |
| 1599 | //request := &StartSoftwareDownloadResponse{ |
| 1600 | // MeBasePacket: MeBasePacket{ |
| 1601 | // EntityClass: OnuDataClassID, |
| 1602 | // // Default Instance ID is 0 |
| 1603 | // }, |
| 1604 | //} |
| 1605 | //// Test serialization back to former string |
| 1606 | //var options gopacket.SerializeOptions |
| 1607 | //options.FixLengths = true |
| 1608 | // |
| 1609 | //buffer := gopacket.NewSerializeBuffer() |
| 1610 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1611 | //assert.NoError(t, err) |
| 1612 | // |
| 1613 | //outgoingPacket := buffer.Bytes() |
| 1614 | //reconstituted := packetToString(outgoingPacket) |
| 1615 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1616 | } |
| 1617 | |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1618 | // 1 2 3 4 |
| 1619 | // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 |
| 1620 | // 0008140a00070001 - Download section, AR=0 |
| 1621 | // cc - Section 0xcc |
| 1622 | // 01020304050607080910111213141516171819202122232425262728293031 |
| 1623 | // 00000028 |
| 1624 | |
| 1625 | func TestDownloadSectionRequestDecodeNoResponseExpected(t *testing.T) { |
| 1626 | goodMessage := "0008140a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1627 | data, err := stringToPacket(goodMessage) |
| 1628 | assert.NoError(t, err) |
| 1629 | |
| 1630 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1631 | assert.NotNil(t, packet) |
| 1632 | |
| 1633 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1634 | assert.NotNil(t, packet) |
| 1635 | |
| 1636 | omciMsg, ok := omciLayer.(*OMCI) |
| 1637 | assert.True(t, ok) |
| 1638 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 1639 | assert.Equal(t, DownloadSectionRequestType, omciMsg.MessageType) |
| 1640 | assert.False(t, omciMsg.ResponseExpected) |
| 1641 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1642 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1643 | |
| 1644 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 1645 | assert.NotNil(t, msgLayer) |
| 1646 | |
| 1647 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 1648 | assert.True(t, ok2) |
| 1649 | assert.NotNil(t, request) |
| 1650 | assert.Equal(t, uint8(0xcc), request.SectionNumber) |
| 1651 | assert.Equal(t, 31, len(request.SectionData)) |
| 1652 | |
| 1653 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1654 | assert.Nil(t, genErr) |
| 1655 | assert.NotNil(t, sectionData) |
| 1656 | assert.Equal(t, 31, len(sectionData)) |
| 1657 | assert.Equal(t, sectionData, request.SectionData[:]) |
| 1658 | |
| 1659 | // Verify string output for message |
| 1660 | packetString := packet.String() |
| 1661 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1662 | } |
| 1663 | |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1664 | func TestDownloadSectionRequestDecodeResponseExpected(t *testing.T) { |
| 1665 | goodMessage := "0008540a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1666 | data, err := stringToPacket(goodMessage) |
| 1667 | assert.NoError(t, err) |
| 1668 | |
| 1669 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1670 | assert.NotNil(t, packet) |
| 1671 | |
| 1672 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1673 | assert.NotNil(t, packet) |
| 1674 | |
| 1675 | omciMsg, ok := omciLayer.(*OMCI) |
| 1676 | assert.True(t, ok) |
| 1677 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 1678 | assert.Equal(t, DownloadSectionRequestWithResponseType, omciMsg.MessageType) |
| 1679 | assert.True(t, omciMsg.ResponseExpected) |
| 1680 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1681 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1682 | |
| 1683 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 1684 | assert.NotNil(t, msgLayer) |
| 1685 | |
| 1686 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 1687 | assert.True(t, ok2) |
| 1688 | assert.NotNil(t, request) |
| 1689 | assert.Equal(t, uint8(0xcc), request.SectionNumber) |
| 1690 | assert.Equal(t, 31, len(request.SectionData)) |
| 1691 | |
| 1692 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1693 | assert.Nil(t, genErr) |
| 1694 | assert.NotNil(t, sectionData) |
| 1695 | assert.Equal(t, 31, len(sectionData)) |
| 1696 | assert.Equal(t, sectionData, request.SectionData[:]) |
| 1697 | |
| 1698 | // Verify string output for message |
| 1699 | packetString := packet.String() |
| 1700 | assert.NotZero(t, len(packetString)) |
| 1701 | } |
| 1702 | |
| 1703 | func TestDownloadSectionRequestSerializeNoResponseExpected(t *testing.T) { |
| 1704 | goodMessage := "0123140a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1705 | |
| 1706 | omciLayer := &OMCI{ |
| 1707 | TransactionID: 0x0123, |
| 1708 | MessageType: DownloadSectionRequestType, |
| 1709 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1710 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1711 | } |
| 1712 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1713 | assert.Nil(t, genErr) |
| 1714 | assert.NotNil(t, sectionData) |
| 1715 | assert.Equal(t, 31, len(sectionData)) |
| 1716 | |
| 1717 | request := &DownloadSectionRequest{ |
| 1718 | MeBasePacket: MeBasePacket{ |
| 1719 | EntityClass: me.SoftwareImageClassID, |
| 1720 | // Default Instance ID is 0 |
| 1721 | }, |
| 1722 | SectionNumber: 0xcc, |
| 1723 | } |
| 1724 | copy(request.SectionData[:], sectionData) |
| 1725 | |
| 1726 | // Test serialization back to former string |
| 1727 | var options gopacket.SerializeOptions |
| 1728 | options.FixLengths = true |
| 1729 | |
| 1730 | buffer := gopacket.NewSerializeBuffer() |
| 1731 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1732 | assert.NoError(t, err) |
| 1733 | |
| 1734 | outgoingPacket := buffer.Bytes() |
| 1735 | reconstituted := packetToString(outgoingPacket) |
| 1736 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1737 | } |
| 1738 | |
| 1739 | func TestDownloadSectionRequestSerializeResponseExpectedMethod1(t *testing.T) { |
| 1740 | goodMessage := "2468540a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1741 | |
| 1742 | omciLayer := &OMCI{ |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame^] | 1743 | TransactionID: 0x2468, |
| 1744 | MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1745 | ResponseExpected: true, |
| 1746 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1747 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1748 | } |
| 1749 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1750 | assert.Nil(t, genErr) |
| 1751 | assert.NotNil(t, sectionData) |
| 1752 | assert.Equal(t, 31, len(sectionData)) |
| 1753 | |
| 1754 | request := &DownloadSectionRequest{ |
| 1755 | MeBasePacket: MeBasePacket{ |
| 1756 | EntityClass: me.SoftwareImageClassID, |
| 1757 | // Default Instance ID is 0 |
| 1758 | }, |
| 1759 | SectionNumber: 0xcc, |
| 1760 | } |
| 1761 | copy(request.SectionData[:], sectionData) |
| 1762 | |
| 1763 | // Test serialization back to former string |
| 1764 | var options gopacket.SerializeOptions |
| 1765 | options.FixLengths = true |
| 1766 | |
| 1767 | buffer := gopacket.NewSerializeBuffer() |
| 1768 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1769 | assert.NoError(t, err) |
| 1770 | |
| 1771 | outgoingPacket := buffer.Bytes() |
| 1772 | reconstituted := packetToString(outgoingPacket) |
| 1773 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1774 | } |
| 1775 | |
| 1776 | func TestDownloadSectionRequestSerializeResponseExpectedMethod2(t *testing.T) { |
| 1777 | goodMessage := "2468540a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1778 | |
| 1779 | // In this case, just use the request type with AR response requested already encoded |
| 1780 | omciLayer := &OMCI{ |
| 1781 | TransactionID: 0x2468, |
| 1782 | MessageType: DownloadSectionRequestWithResponseType, |
| 1783 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1784 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1785 | } |
| 1786 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1787 | assert.Nil(t, genErr) |
| 1788 | assert.NotNil(t, sectionData) |
| 1789 | assert.Equal(t, 31, len(sectionData)) |
| 1790 | |
| 1791 | request := &DownloadSectionRequest{ |
| 1792 | MeBasePacket: MeBasePacket{ |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame^] | 1793 | EntityClass: me.SoftwareImageClassID, |
| 1794 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1795 | }, |
| 1796 | SectionNumber: 0xcc, |
| 1797 | } |
| 1798 | copy(request.SectionData[:], sectionData) |
| 1799 | |
| 1800 | // Test serialization back to former string |
| 1801 | var options gopacket.SerializeOptions |
| 1802 | options.FixLengths = true |
| 1803 | |
| 1804 | buffer := gopacket.NewSerializeBuffer() |
| 1805 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1806 | assert.NoError(t, err) |
| 1807 | |
| 1808 | outgoingPacket := buffer.Bytes() |
| 1809 | reconstituted := packetToString(outgoingPacket) |
| 1810 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | func TestDownloadSectionResponseDecode(t *testing.T) { |
| 1814 | // TODO: Need to complete implementation & debug this |
| 1815 | //goodMessage := "" |
| 1816 | //data, err := stringToPacket(goodMessage) |
| 1817 | //assert.NoError(t, err) |
| 1818 | // |
| 1819 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1820 | //assert.NotNil(t, packet) |
| 1821 | // |
| 1822 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1823 | //assert.NotNil(t, packet) |
| 1824 | // |
| 1825 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1826 | //assert.True(t, ok) |
| 1827 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1828 | //assert.Equal(t, omciMsg.MessageType, DownloadSectionResponseType) |
| 1829 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1830 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1831 | // |
| 1832 | //msgLayer := packet.Layer(LayerTypeDownloadSectionResponse) |
| 1833 | // |
| 1834 | //assert.NotNil(t, msgLayer) |
| 1835 | // |
| 1836 | //response, ok2 := msgLayer.(*DownloadSectionResponse) |
| 1837 | //assert.True(t, ok2) |
| 1838 | //assert.NotNil(t, response) |
| 1839 | // |
| 1840 | //// Verify string output for message |
| 1841 | //packetString := packet.String() |
| 1842 | //assert.NotZero(t, len(packetString)) |
| 1843 | } |
| 1844 | |
| 1845 | func TestDownloadSectionResponseSerialize(t *testing.T) { |
| 1846 | // TODO: Need to complete implementation & debug this |
| 1847 | //goodMessage := "" |
| 1848 | // |
| 1849 | //omciLayer := &OMCI{ |
| 1850 | // TransactionID: 0x01, |
| 1851 | // MessageType: DownloadSectionResponseType, |
| 1852 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1853 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1854 | //} |
| 1855 | //request := &DownloadSectionResponse{ |
| 1856 | // MeBasePacket: MeBasePacket{ |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1857 | // EntityClass: me.OnuDataClassID, |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1858 | // // Default Instance ID is 0 |
| 1859 | // }, |
| 1860 | //} |
| 1861 | //// Test serialization back to former string |
| 1862 | //var options gopacket.SerializeOptions |
| 1863 | //options.FixLengths = true |
| 1864 | // |
| 1865 | //buffer := gopacket.NewSerializeBuffer() |
| 1866 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1867 | //assert.NoError(t, err) |
| 1868 | // |
| 1869 | //outgoingPacket := buffer.Bytes() |
| 1870 | //reconstituted := packetToString(outgoingPacket) |
| 1871 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1872 | } |
| 1873 | |
| 1874 | func TestEndSoftwareDownloadRequestDecode(t *testing.T) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1875 | // |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame^] | 1876 | // 8100 55 0a 0007 0001 ff92a226 000f4240 01 0001 00000000000000000000000000000000000000000000000028 |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1877 | // |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame^] | 1878 | goodMessage := "8100550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028" |
| 1879 | data, err := stringToPacket(goodMessage) |
| 1880 | assert.NoError(t, err) |
| 1881 | |
| 1882 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1883 | assert.NotNil(t, packet) |
| 1884 | |
| 1885 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1886 | assert.NotNil(t, packet) |
| 1887 | |
| 1888 | omciMsg, ok := omciLayer.(*OMCI) |
| 1889 | assert.True(t, ok) |
| 1890 | assert.Equal(t, omciMsg.TransactionID, uint16(0x8100)) |
| 1891 | assert.Equal(t, omciMsg.MessageType, EndSoftwareDownloadRequestType) |
| 1892 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1893 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1894 | |
| 1895 | msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadRequest) |
| 1896 | assert.NotNil(t, msgLayer) |
| 1897 | |
| 1898 | request, ok2 := msgLayer.(*EndSoftwareDownloadRequest) |
| 1899 | assert.True(t, ok2) |
| 1900 | assert.NotNil(t, request) |
| 1901 | assert.Equal(t, uint32(0xff92a226), request.CRC32) |
| 1902 | assert.Equal(t, uint32(0x000f4240), request.ImageSize) |
| 1903 | assert.Equal(t, byte(1), request.NumberOfInstances) |
| 1904 | assert.Equal(t, 1, len(request.ImageInstances)) |
| 1905 | assert.Equal(t, uint16(1), request.ImageInstances[0]) |
| 1906 | |
| 1907 | // Verify string output for message |
| 1908 | packetString := packet.String() |
| 1909 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | func TestEndSoftwareDownloadRequestSerialize(t *testing.T) { |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame^] | 1913 | // 8100 55 0a 0007 0001 ff92a226 000f4240 01 0001 00000000000000000000000000000000000000000000000028 |
| 1914 | goodMessage := "8100550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028" |
| 1915 | |
| 1916 | omciLayer := &OMCI{ |
| 1917 | TransactionID: 0x8100, |
| 1918 | MessageType: EndSoftwareDownloadRequestType, |
| 1919 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1920 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1921 | } |
| 1922 | request := &EndSoftwareDownloadRequest{ |
| 1923 | MeBasePacket: MeBasePacket{ |
| 1924 | EntityClass: me.SoftwareImageClassID, |
| 1925 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
| 1926 | }, |
| 1927 | CRC32: 0xff92a226, |
| 1928 | ImageSize: 1000000, |
| 1929 | NumberOfInstances: 1, |
| 1930 | ImageInstances: []uint16{1}, |
| 1931 | } |
| 1932 | // Test serialization back to former string |
| 1933 | var options gopacket.SerializeOptions |
| 1934 | options.FixLengths = true |
| 1935 | |
| 1936 | buffer := gopacket.NewSerializeBuffer() |
| 1937 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1938 | assert.NoError(t, err) |
| 1939 | |
| 1940 | outgoingPacket := buffer.Bytes() |
| 1941 | reconstituted := packetToString(outgoingPacket) |
| 1942 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | func TestEndSoftwareDownloadResponseDecode(t *testing.T) { |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame^] | 1946 | // 8123 35 0a 0007 0001 06 0000000000000000000000000000000000000000000000000000000000000000000028 |
| 1947 | goodMessage := "8123350a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 1948 | data, err := stringToPacket(goodMessage) |
| 1949 | assert.NoError(t, err) |
| 1950 | |
| 1951 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1952 | assert.NotNil(t, packet) |
| 1953 | |
| 1954 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1955 | assert.NotNil(t, packet) |
| 1956 | |
| 1957 | omciMsg, ok := omciLayer.(*OMCI) |
| 1958 | assert.True(t, ok) |
| 1959 | assert.Equal(t, omciMsg.TransactionID, uint16(0x8123)) |
| 1960 | assert.Equal(t, omciMsg.MessageType, EndSoftwareDownloadResponseType) |
| 1961 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1962 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1963 | |
| 1964 | msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadResponse) |
| 1965 | assert.NotNil(t, msgLayer) |
| 1966 | |
| 1967 | response, ok2 := msgLayer.(*EndSoftwareDownloadResponse) |
| 1968 | assert.True(t, ok2) |
| 1969 | assert.NotNil(t, response) |
| 1970 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 1971 | assert.Equal(t, byte(0), response.NumberOfInstances) |
| 1972 | assert.Nil(t, response.MeResults) |
| 1973 | |
| 1974 | // Verify string output for message |
| 1975 | packetString := packet.String() |
| 1976 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | func TestEndSoftwareDownloadResponseSerialize(t *testing.T) { |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame^] | 1980 | goodMessage := "8456350a00070000010000000000000000000000000000000000000000000000000000000000000000000028" |
| 1981 | |
| 1982 | omciLayer := &OMCI{ |
| 1983 | TransactionID: 0x8456, |
| 1984 | MessageType: EndSoftwareDownloadResponseType, |
| 1985 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1986 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1987 | } |
| 1988 | request := &EndSoftwareDownloadResponse{ |
| 1989 | MeBasePacket: MeBasePacket{ |
| 1990 | EntityClass: me.SoftwareImageClassID, |
| 1991 | // Default is zero |
| 1992 | }, |
| 1993 | Result: me.ProcessingError, |
| 1994 | NumberOfInstances: 0, |
| 1995 | } |
| 1996 | // Test serialization back to former string |
| 1997 | var options gopacket.SerializeOptions |
| 1998 | options.FixLengths = true |
| 1999 | |
| 2000 | buffer := gopacket.NewSerializeBuffer() |
| 2001 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2002 | assert.NoError(t, err) |
| 2003 | |
| 2004 | outgoingPacket := buffer.Bytes() |
| 2005 | reconstituted := packetToString(outgoingPacket) |
| 2006 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | func TestActivateSoftwareRequestDecode(t *testing.T) { |
| 2010 | // TODO: Need to complete implementation & debug this |
| 2011 | //goodMessage := "0000560a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2012 | //data, err := stringToPacket(goodMessage) |
| 2013 | //assert.NoError(t, err) |
| 2014 | // |
| 2015 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2016 | //assert.NotNil(t, packet) |
| 2017 | // |
| 2018 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 2019 | //assert.NotNil(t, packet) |
| 2020 | // |
| 2021 | //omciMsg, ok := omciLayer.(*OMCI) |
| 2022 | //assert.True(t, ok) |
| 2023 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2024 | //assert.Equal(t, omciMsg.MessageType, ActivateSoftwareRequestType) |
| 2025 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2026 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2027 | // |
| 2028 | //msgLayer := packet.Layer(LayerTypeActivateSoftwareRequest) |
| 2029 | //assert.NotNil(t, msgLayer) |
| 2030 | // |
| 2031 | //request, ok2 := msgLayer.(*ActivateSoftwareRequest) |
| 2032 | //assert.True(t, ok2) |
| 2033 | //assert.NotNil(t, request) |
| 2034 | // |
| 2035 | //// Verify string output for message |
| 2036 | //packetString := packet.String() |
| 2037 | //assert.NotZero(t, len(packetString)) |
| 2038 | } |
| 2039 | |
| 2040 | func TestActivateSoftwareRequestSerialize(t *testing.T) { |
| 2041 | // TODO: Need to complete implementation & debug this |
| 2042 | //goodMessage := "0000560a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2043 | // |
| 2044 | //omciLayer := &OMCI{ |
| 2045 | // TransactionID: 0x01, |
| 2046 | // MessageType: ActivateSoftwareRequestType, |
| 2047 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2048 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 2049 | //} |
| 2050 | //request := &ActivateSoftwareRequest{ |
| 2051 | // MeBasePacket: MeBasePacket{ |
| 2052 | // EntityClass: OnuDataClassID, |
| 2053 | // // Default Instance ID is 0 |
| 2054 | // }, |
| 2055 | //} |
| 2056 | //// Test serialization back to former string |
| 2057 | //var options gopacket.SerializeOptions |
| 2058 | //options.FixLengths = true |
| 2059 | // |
| 2060 | //buffer := gopacket.NewSerializeBuffer() |
| 2061 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2062 | //assert.NoError(t, err) |
| 2063 | // |
| 2064 | //outgoingPacket := buffer.Bytes() |
| 2065 | //reconstituted := packetToString(outgoingPacket) |
| 2066 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2067 | } |
| 2068 | |
| 2069 | func TestActivateSoftwareResponseDecode(t *testing.T) { |
| 2070 | // TODO: Need to complete implementation & debug this |
| 2071 | //goodMessage := "" |
| 2072 | //data, err := stringToPacket(goodMessage) |
| 2073 | //assert.NoError(t, err) |
| 2074 | // |
| 2075 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2076 | //assert.NotNil(t, packet) |
| 2077 | // |
| 2078 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 2079 | //assert.NotNil(t, packet) |
| 2080 | // |
| 2081 | //omciMsg, ok := omciLayer.(*OMCI) |
| 2082 | //assert.True(t, ok) |
| 2083 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2084 | //assert.Equal(t, omciMsg.MessageType, ActivateSoftwareResponseType) |
| 2085 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2086 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2087 | // |
| 2088 | //msgLayer := packet.Layer(LayerTypeActivateSoftwareResponse) |
| 2089 | // |
| 2090 | //assert.NotNil(t, msgLayer) |
| 2091 | // |
| 2092 | //response, ok2 := msgLayer.(*ActivateSoftwareResponse) |
| 2093 | //assert.True(t, ok2) |
| 2094 | //assert.NotNil(t, response) |
| 2095 | // |
| 2096 | //// Verify string output for message |
| 2097 | //packetString := packet.String() |
| 2098 | //assert.NotZero(t, len(packetString)) |
| 2099 | } |
| 2100 | |
| 2101 | func TestActivateSoftwareResponseSerialize(t *testing.T) { |
| 2102 | // TODO: Need to complete implementation & debug this |
| 2103 | //goodMessage := "" |
| 2104 | // |
| 2105 | //omciLayer := &OMCI{ |
| 2106 | // TransactionID: 0x01, |
| 2107 | // MessageType: ActivateSoftwareResponseType, |
| 2108 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2109 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 2110 | //} |
| 2111 | //request := &ActivateSoftwareResponse{ |
| 2112 | // MeBasePacket: MeBasePacket{ |
| 2113 | // EntityClass: OnuDataClassID, |
| 2114 | // // Default Instance ID is 0 |
| 2115 | // }, |
| 2116 | //} |
| 2117 | //// Test serialization back to former string |
| 2118 | //var options gopacket.SerializeOptions |
| 2119 | //options.FixLengths = true |
| 2120 | // |
| 2121 | //buffer := gopacket.NewSerializeBuffer() |
| 2122 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2123 | //assert.NoError(t, err) |
| 2124 | // |
| 2125 | //outgoingPacket := buffer.Bytes() |
| 2126 | //reconstituted := packetToString(outgoingPacket) |
| 2127 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2128 | } |
| 2129 | |
| 2130 | func TestCommitSoftwareRequestDecode(t *testing.T) { |
| 2131 | // TODO: Need to complete implementation & debug this |
| 2132 | //goodMessage := "0000570a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2133 | //data, err := stringToPacket(goodMessage) |
| 2134 | //assert.NoError(t, err) |
| 2135 | // |
| 2136 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2137 | //assert.NotNil(t, packet) |
| 2138 | // |
| 2139 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 2140 | //assert.NotNil(t, packet) |
| 2141 | // |
| 2142 | //omciMsg, ok := omciLayer.(*OMCI) |
| 2143 | //assert.True(t, ok) |
| 2144 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2145 | //assert.Equal(t, omciMsg.MessageType, CommitSoftwareRequestType) |
| 2146 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2147 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2148 | // |
| 2149 | //msgLayer := packet.Layer(LayerTypeCommitSoftwareRequest) |
| 2150 | //assert.NotNil(t, msgLayer) |
| 2151 | // |
| 2152 | //request, ok2 := msgLayer.(*CommitSoftwareRequest) |
| 2153 | //assert.True(t, ok2) |
| 2154 | //assert.NotNil(t, request) |
| 2155 | // |
| 2156 | //// Verify string output for message |
| 2157 | //packetString := packet.String() |
| 2158 | //assert.NotZero(t, len(packetString)) |
| 2159 | } |
| 2160 | |
| 2161 | func TestCommitSoftwareRequestSerialize(t *testing.T) { |
| 2162 | // TODO: Need to complete implementation & debug this |
| 2163 | //goodMessage := "0000570a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2164 | // |
| 2165 | //omciLayer := &OMCI{ |
| 2166 | // TransactionID: 0x01, |
| 2167 | // MessageType: CommitSoftwareRequestType, |
| 2168 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2169 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 2170 | //} |
| 2171 | //request := &CommitSoftwareRequest{ |
| 2172 | // MeBasePacket: MeBasePacket{ |
| 2173 | // EntityClass: OnuDataClassID, |
| 2174 | // // Default Instance ID is 0 |
| 2175 | // }, |
| 2176 | //} |
| 2177 | //// Test serialization back to former string |
| 2178 | //var options gopacket.SerializeOptions |
| 2179 | //options.FixLengths = true |
| 2180 | // |
| 2181 | //buffer := gopacket.NewSerializeBuffer() |
| 2182 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2183 | //assert.NoError(t, err) |
| 2184 | // |
| 2185 | //outgoingPacket := buffer.Bytes() |
| 2186 | //reconstituted := packetToString(outgoingPacket) |
| 2187 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2188 | } |
| 2189 | |
| 2190 | func TestCommitSoftwareResponseDecode(t *testing.T) { |
| 2191 | // TODO: Need to complete implementation & debug this |
| 2192 | //goodMessage := "" |
| 2193 | //data, err := stringToPacket(goodMessage) |
| 2194 | //assert.NoError(t, err) |
| 2195 | // |
| 2196 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2197 | //assert.NotNil(t, packet) |
| 2198 | // |
| 2199 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 2200 | //assert.NotNil(t, packet) |
| 2201 | // |
| 2202 | //omciMsg, ok := omciLayer.(*OMCI) |
| 2203 | //assert.True(t, ok) |
| 2204 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2205 | //assert.Equal(t, omciMsg.MessageType, CommitSoftwareResponseType) |
| 2206 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2207 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2208 | // |
| 2209 | //msgLayer := packet.Layer(LayerTypeCommitSoftwareResponse) |
| 2210 | // |
| 2211 | //assert.NotNil(t, msgLayer) |
| 2212 | // |
| 2213 | //response, ok2 := msgLayer.(*CommitSoftwareResponse) |
| 2214 | //assert.True(t, ok2) |
| 2215 | //assert.NotNil(t, response) |
| 2216 | // |
| 2217 | //// Verify string output for message |
| 2218 | //packetString := packet.String() |
| 2219 | //assert.NotZero(t, len(packetString)) |
| 2220 | } |
| 2221 | |
| 2222 | func TestCommitSoftwareResponseSerialize(t *testing.T) { |
| 2223 | // TODO: Need to complete implementation & debug this |
| 2224 | //goodMessage := "" |
| 2225 | // |
| 2226 | //omciLayer := &OMCI{ |
| 2227 | // TransactionID: 0x01, |
| 2228 | // MessageType: CommitSoftwareResponseType, |
| 2229 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2230 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 2231 | //} |
| 2232 | //request := &CommitSoftwareResponse{ |
| 2233 | // MeBasePacket: MeBasePacket{ |
| 2234 | // EntityClass: OnuDataClassID, |
| 2235 | // // Default Instance ID is 0 |
| 2236 | // }, |
| 2237 | //} |
| 2238 | //// Test serialization back to former string |
| 2239 | //var options gopacket.SerializeOptions |
| 2240 | //options.FixLengths = true |
| 2241 | // |
| 2242 | //buffer := gopacket.NewSerializeBuffer() |
| 2243 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2244 | //assert.NoError(t, err) |
| 2245 | // |
| 2246 | //outgoingPacket := buffer.Bytes() |
| 2247 | //reconstituted := packetToString(outgoingPacket) |
| 2248 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2249 | } |
| 2250 | |
| 2251 | func TestMibResetResponseDecode(t *testing.T) { |
| 2252 | goodMessage := "00012F0A00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2253 | data, err := stringToPacket(goodMessage) |
| 2254 | assert.NoError(t, err) |
| 2255 | |
| 2256 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2257 | assert.NotNil(t, packet) |
| 2258 | |
| 2259 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2260 | assert.NotNil(t, packet) |
| 2261 | |
| 2262 | omciMsg, ok := omciLayer.(*OMCI) |
| 2263 | assert.True(t, ok) |
| 2264 | assert.Equal(t, omciMsg.MessageType, MibResetResponseType) |
| 2265 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2266 | |
| 2267 | msgLayer := packet.Layer(LayerTypeMibResetResponse) |
| 2268 | |
| 2269 | assert.NotNil(t, msgLayer) |
| 2270 | |
| 2271 | response, ok2 := msgLayer.(*MibResetResponse) |
| 2272 | assert.True(t, ok2) |
| 2273 | assert.NotNil(t, response) |
| 2274 | |
| 2275 | // Verify string output for message |
| 2276 | packetString := packet.String() |
| 2277 | assert.NotZero(t, len(packetString)) |
| 2278 | } |
| 2279 | |
| 2280 | func TestMibResetResponseSerialize(t *testing.T) { |
| 2281 | goodMessage := "00012F0A00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2282 | |
| 2283 | omciLayer := &OMCI{ |
| 2284 | TransactionID: 0x01, |
| 2285 | MessageType: MibResetResponseType, |
| 2286 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2287 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2288 | } |
| 2289 | request := &MibResetResponse{ |
| 2290 | MeBasePacket: MeBasePacket{ |
| 2291 | EntityClass: me.OnuDataClassID, |
| 2292 | // Default Instance ID is 0 |
| 2293 | }, |
| 2294 | } |
| 2295 | // Test serialization back to former string |
| 2296 | var options gopacket.SerializeOptions |
| 2297 | options.FixLengths = true |
| 2298 | |
| 2299 | buffer := gopacket.NewSerializeBuffer() |
| 2300 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2301 | assert.NoError(t, err) |
| 2302 | |
| 2303 | outgoingPacket := buffer.Bytes() |
| 2304 | reconstituted := packetToString(outgoingPacket) |
| 2305 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2306 | } |
| 2307 | |
| 2308 | func TestSynchronizeTimeRequestDecode(t *testing.T) { |
| 2309 | goodMessage := "0109580a0100000007e20c0101301b0000000000000000000000000000000000000000000000000000000028" |
| 2310 | data, err := stringToPacket(goodMessage) |
| 2311 | assert.NoError(t, err) |
| 2312 | |
| 2313 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2314 | assert.NotNil(t, packet) |
| 2315 | |
| 2316 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2317 | assert.NotNil(t, packet) |
| 2318 | |
| 2319 | omciMsg, ok := omciLayer.(*OMCI) |
| 2320 | assert.True(t, ok) |
| 2321 | assert.Equal(t, omciMsg.MessageType, SynchronizeTimeRequestType) |
| 2322 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2323 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2324 | |
| 2325 | msgLayer := packet.Layer(LayerTypeSynchronizeTimeRequest) |
| 2326 | assert.NotNil(t, msgLayer) |
| 2327 | |
| 2328 | request, ok2 := msgLayer.(*SynchronizeTimeRequest) |
| 2329 | assert.True(t, ok2) |
| 2330 | assert.NotNil(t, request) |
| 2331 | assert.Equal(t, request.Year, uint16(2018)) |
| 2332 | assert.Equal(t, request.Month, uint8(12)) |
| 2333 | assert.Equal(t, request.Day, uint8(1)) |
| 2334 | assert.Equal(t, request.Hour, uint8(01)) |
| 2335 | assert.Equal(t, request.Minute, uint8(48)) |
| 2336 | assert.Equal(t, request.Second, uint8(27)) |
| 2337 | |
| 2338 | // Verify string output for message |
| 2339 | packetString := packet.String() |
| 2340 | assert.NotZero(t, len(packetString)) |
| 2341 | } |
| 2342 | |
| 2343 | func TestSynchronizeTimeRequestSerialize(t *testing.T) { |
| 2344 | goodMessage := "0109580a0100000007e20c0101301b0000000000000000000000000000000000000000000000000000000028" |
| 2345 | |
| 2346 | omciLayer := &OMCI{ |
| 2347 | TransactionID: 0x0109, |
| 2348 | MessageType: SynchronizeTimeRequestType, |
| 2349 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2350 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2351 | } |
| 2352 | request := &SynchronizeTimeRequest{ |
| 2353 | MeBasePacket: MeBasePacket{ |
| 2354 | EntityClass: me.OnuGClassID, |
| 2355 | // Default Instance ID is 0 |
| 2356 | }, |
| 2357 | Year: uint16(2018), |
| 2358 | Month: uint8(12), |
| 2359 | Day: uint8(1), |
| 2360 | Hour: uint8(01), |
| 2361 | Minute: uint8(48), |
| 2362 | Second: uint8(27), |
| 2363 | } |
| 2364 | // Test serialization back to former string |
| 2365 | var options gopacket.SerializeOptions |
| 2366 | options.FixLengths = true |
| 2367 | |
| 2368 | buffer := gopacket.NewSerializeBuffer() |
| 2369 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2370 | assert.NoError(t, err) |
| 2371 | |
| 2372 | outgoingPacket := buffer.Bytes() |
| 2373 | reconstituted := packetToString(outgoingPacket) |
| 2374 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2375 | } |
| 2376 | |
| 2377 | func TestSynchronizeTimeResponseDecode(t *testing.T) { |
| 2378 | goodMessage := "0109380a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2379 | data, err := stringToPacket(goodMessage) |
| 2380 | assert.NoError(t, err) |
| 2381 | |
| 2382 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2383 | assert.NotNil(t, packet) |
| 2384 | |
| 2385 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2386 | assert.NotNil(t, packet) |
| 2387 | |
| 2388 | omciMsg, ok := omciLayer.(*OMCI) |
| 2389 | assert.True(t, ok) |
| 2390 | assert.Equal(t, omciMsg.MessageType, SynchronizeTimeResponseType) |
| 2391 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2392 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2393 | |
| 2394 | msgLayer := packet.Layer(LayerTypeSynchronizeTimeResponse) |
| 2395 | assert.NotNil(t, msgLayer) |
| 2396 | |
| 2397 | response, ok2 := msgLayer.(*SynchronizeTimeResponse) |
| 2398 | assert.True(t, ok2) |
| 2399 | assert.NotNil(t, response) |
| 2400 | |
| 2401 | // Verify string output for message |
| 2402 | packetString := packet.String() |
| 2403 | assert.NotZero(t, len(packetString)) |
| 2404 | } |
| 2405 | |
| 2406 | func TestSynchronizeTimeResponseSerialize(t *testing.T) { |
| 2407 | goodMessage := "0109380a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2408 | |
| 2409 | omciLayer := &OMCI{ |
| 2410 | TransactionID: 0x0109, |
| 2411 | MessageType: SynchronizeTimeResponseType, |
| 2412 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2413 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2414 | } |
| 2415 | request := &SynchronizeTimeResponse{ |
| 2416 | MeBasePacket: MeBasePacket{ |
| 2417 | EntityClass: me.OnuGClassID, |
| 2418 | EntityInstance: uint16(0), |
| 2419 | }, |
| 2420 | Result: me.Success, |
| 2421 | SuccessResults: uint8(0), |
| 2422 | } |
| 2423 | // Test serialization back to former string |
| 2424 | var options gopacket.SerializeOptions |
| 2425 | options.FixLengths = true |
| 2426 | |
| 2427 | buffer := gopacket.NewSerializeBuffer() |
| 2428 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2429 | assert.NoError(t, err) |
| 2430 | |
| 2431 | outgoingPacket := buffer.Bytes() |
| 2432 | reconstituted := packetToString(outgoingPacket) |
| 2433 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2434 | } |
| 2435 | |
| 2436 | func TestRebootRequestDecode(t *testing.T) { |
| 2437 | goodMessage := "0001590a01000000010000000000000000000000000000000000000000000000000000000000000000000028" |
| 2438 | data, err := stringToPacket(goodMessage) |
| 2439 | assert.NoError(t, err) |
| 2440 | |
| 2441 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2442 | assert.NotNil(t, packet) |
| 2443 | |
| 2444 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2445 | assert.NotNil(t, packet) |
| 2446 | |
| 2447 | omciMsg, ok := omciLayer.(*OMCI) |
| 2448 | assert.True(t, ok) |
| 2449 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0001)) |
| 2450 | assert.Equal(t, omciMsg.MessageType, RebootRequestType) |
| 2451 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2452 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2453 | |
| 2454 | msgLayer := packet.Layer(LayerTypeRebootRequest) |
| 2455 | assert.NotNil(t, msgLayer) |
| 2456 | |
| 2457 | request, ok2 := msgLayer.(*RebootRequest) |
| 2458 | assert.True(t, ok2) |
| 2459 | assert.NotNil(t, request) |
| 2460 | assert.Equal(t, request.EntityClass, me.OnuGClassID) |
| 2461 | assert.Equal(t, request.EntityInstance, uint16(0)) |
| 2462 | assert.Equal(t, request.RebootCondition, uint8(1)) |
| 2463 | |
| 2464 | // Verify string output for message |
| 2465 | packetString := packet.String() |
| 2466 | assert.NotZero(t, len(packetString)) |
| 2467 | } |
| 2468 | |
| 2469 | func TestRebootRequestSerialize(t *testing.T) { |
| 2470 | goodMessage := "0001590a01000000020000000000000000000000000000000000000000000000000000000000000000000028" |
| 2471 | |
| 2472 | omciLayer := &OMCI{ |
| 2473 | TransactionID: 0x0001, |
| 2474 | MessageType: RebootRequestType, |
| 2475 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2476 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2477 | } |
| 2478 | request := &RebootRequest{ |
| 2479 | MeBasePacket: MeBasePacket{ |
| 2480 | EntityClass: me.OnuGClassID, |
| 2481 | // Default Instance ID is 0 |
| 2482 | }, |
| 2483 | RebootCondition: uint8(2), |
| 2484 | } |
| 2485 | // Test serialization back to former string |
| 2486 | var options gopacket.SerializeOptions |
| 2487 | options.FixLengths = true |
| 2488 | |
| 2489 | buffer := gopacket.NewSerializeBuffer() |
| 2490 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2491 | assert.NoError(t, err) |
| 2492 | |
| 2493 | outgoingPacket := buffer.Bytes() |
| 2494 | reconstituted := packetToString(outgoingPacket) |
| 2495 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2496 | } |
| 2497 | |
| 2498 | func TestRebootResponseDecode(t *testing.T) { |
| 2499 | goodMessage := "023c390a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2500 | data, err := stringToPacket(goodMessage) |
| 2501 | assert.NoError(t, err) |
| 2502 | |
| 2503 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2504 | assert.NotNil(t, packet) |
| 2505 | |
| 2506 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2507 | assert.NotNil(t, packet) |
| 2508 | |
| 2509 | omciMsg, ok := omciLayer.(*OMCI) |
| 2510 | assert.True(t, ok) |
| 2511 | assert.Equal(t, omciMsg.TransactionID, uint16(0x023c)) |
| 2512 | assert.Equal(t, omciMsg.MessageType, RebootResponseType) |
| 2513 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2514 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2515 | |
| 2516 | msgLayer := packet.Layer(LayerTypeRebootResponse) |
| 2517 | assert.NotNil(t, msgLayer) |
| 2518 | |
| 2519 | response, ok2 := msgLayer.(*RebootResponse) |
| 2520 | assert.True(t, ok2) |
| 2521 | assert.NotNil(t, response) |
| 2522 | assert.Equal(t, response.EntityClass, me.OnuGClassID) |
| 2523 | assert.Equal(t, response.EntityInstance, uint16(0)) |
| 2524 | assert.Equal(t, response.Result, me.Success) |
| 2525 | |
| 2526 | // Verify string output for message |
| 2527 | packetString := packet.String() |
| 2528 | assert.NotZero(t, len(packetString)) |
| 2529 | } |
| 2530 | |
| 2531 | func TestRebootResponseSerialize(t *testing.T) { |
| 2532 | goodMessage := "023c390a01000000060000000000000000000000000000000000000000000000000000000000000000000028" |
| 2533 | |
| 2534 | omciLayer := &OMCI{ |
| 2535 | TransactionID: 0x023c, |
| 2536 | MessageType: RebootResponseType, |
| 2537 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2538 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2539 | } |
| 2540 | request := &RebootResponse{ |
| 2541 | MeBasePacket: MeBasePacket{ |
| 2542 | EntityClass: me.OnuGClassID, |
| 2543 | EntityInstance: uint16(0), |
| 2544 | }, |
| 2545 | Result: me.DeviceBusy, |
| 2546 | } |
| 2547 | // Test serialization back to former string |
| 2548 | var options gopacket.SerializeOptions |
| 2549 | options.FixLengths = true |
| 2550 | |
| 2551 | buffer := gopacket.NewSerializeBuffer() |
| 2552 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2553 | assert.NoError(t, err) |
| 2554 | |
| 2555 | outgoingPacket := buffer.Bytes() |
| 2556 | reconstituted := packetToString(outgoingPacket) |
| 2557 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2558 | } |
| 2559 | |
| 2560 | func TestGetNextRequestDecode(t *testing.T) { |
| 2561 | goodMessage := "285e5a0a00ab0202040000010000000000000000000000000000000000000000000000000000000000000028" |
| 2562 | data, err := stringToPacket(goodMessage) |
| 2563 | assert.NoError(t, err) |
| 2564 | |
| 2565 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2566 | assert.NotNil(t, packet) |
| 2567 | |
| 2568 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2569 | assert.NotNil(t, packet) |
| 2570 | |
| 2571 | omciMsg, ok := omciLayer.(*OMCI) |
| 2572 | assert.True(t, ok) |
| 2573 | assert.Equal(t, omciMsg.TransactionID, uint16(0x285e)) |
| 2574 | assert.Equal(t, omciMsg.MessageType, GetNextRequestType) |
| 2575 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2576 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2577 | |
| 2578 | msgLayer := packet.Layer(LayerTypeGetNextRequest) |
| 2579 | assert.NotNil(t, msgLayer) |
| 2580 | |
| 2581 | request, ok2 := msgLayer.(*GetNextRequest) |
| 2582 | assert.True(t, ok2) |
| 2583 | assert.NotNil(t, request) |
| 2584 | assert.Equal(t, request.EntityClass, me.ExtendedVlanTaggingOperationConfigurationDataClassID) |
| 2585 | assert.Equal(t, request.EntityInstance, uint16(0x0202)) |
| 2586 | assert.Equal(t, request.AttributeMask, uint16(0x0400)) |
| 2587 | assert.Equal(t, request.SequenceNumber, uint16(1)) |
| 2588 | |
| 2589 | // Verify string output for message |
| 2590 | packetString := packet.String() |
| 2591 | assert.NotZero(t, len(packetString)) |
| 2592 | } |
| 2593 | |
| 2594 | func TestGetNextRequestSerialize(t *testing.T) { |
| 2595 | goodMessage := "285e5a0a00ab0202040000010000000000000000000000000000000000000000000000000000000000000028" |
| 2596 | |
| 2597 | omciLayer := &OMCI{ |
| 2598 | TransactionID: 0x285e, |
| 2599 | MessageType: GetNextRequestType, |
| 2600 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2601 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2602 | } |
| 2603 | request := &GetNextRequest{ |
| 2604 | MeBasePacket: MeBasePacket{ |
| 2605 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 2606 | EntityInstance: uint16(0x0202), |
| 2607 | }, |
| 2608 | AttributeMask: uint16(0x0400), |
| 2609 | SequenceNumber: uint16(1), |
| 2610 | } |
| 2611 | // Test serialization back to former string |
| 2612 | var options gopacket.SerializeOptions |
| 2613 | options.FixLengths = true |
| 2614 | |
| 2615 | buffer := gopacket.NewSerializeBuffer() |
| 2616 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2617 | assert.NoError(t, err) |
| 2618 | |
| 2619 | outgoingPacket := buffer.Bytes() |
| 2620 | reconstituted := packetToString(outgoingPacket) |
| 2621 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2622 | } |
| 2623 | |
| 2624 | func TestGetNextResponseDecode(t *testing.T) { |
| 2625 | goodMessage := "285e3a0a00ab0202000400080334000000000000000000000000000000000000000000000000000000000028" |
| 2626 | |
| 2627 | data, err := stringToPacket(goodMessage) |
| 2628 | assert.NoError(t, err) |
| 2629 | |
| 2630 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2631 | assert.NotNil(t, packet) |
| 2632 | |
| 2633 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2634 | assert.NotNil(t, packet) |
| 2635 | |
| 2636 | omciMsg, ok := omciLayer.(*OMCI) |
| 2637 | assert.True(t, ok) |
| 2638 | assert.Equal(t, omciMsg.TransactionID, uint16(0x285e)) |
| 2639 | assert.Equal(t, omciMsg.MessageType, GetNextResponseType) |
| 2640 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2641 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2642 | |
| 2643 | msgLayer := packet.Layer(LayerTypeGetNextResponse) |
| 2644 | assert.NotNil(t, msgLayer) |
| 2645 | |
| 2646 | vlanOpTable := []byte{0x08, 0x03, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2647 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 2648 | |
| 2649 | response, ok2 := msgLayer.(*GetNextResponse) |
| 2650 | assert.True(t, ok2) |
| 2651 | assert.NotNil(t, response) |
| 2652 | assert.Equal(t, me.ExtendedVlanTaggingOperationConfigurationDataClassID, response.EntityClass) |
| 2653 | assert.Equal(t, uint16(0x0202), response.EntityInstance) |
| 2654 | assert.Equal(t, me.Success, response.Result) |
| 2655 | assert.Equal(t, uint16(0x0400), response.AttributeMask) |
| 2656 | |
| 2657 | // For GetNextResponse frames, caller is responsible for trimming last packet to remaining |
| 2658 | // size |
| 2659 | expectedOctets := 16 |
| 2660 | value := response.Attributes["ReceivedFrameVlanTaggingOperationTable"] |
| 2661 | assert.Equal(t, vlanOpTable, value.([]byte)[:expectedOctets]) |
| 2662 | |
| 2663 | // Verify string output for message |
| 2664 | packetString := packet.String() |
| 2665 | assert.NotZero(t, len(packetString)) |
| 2666 | } |
| 2667 | |
| 2668 | func TestGetNextResponseSerialize(t *testing.T) { |
| 2669 | goodMessage := "285e3a0a00ab0202000400080334000000000000000000000000000000000000000000000000000000000028" |
| 2670 | |
| 2671 | omciLayer := &OMCI{ |
| 2672 | TransactionID: 0x285e, |
| 2673 | MessageType: GetNextResponseType, |
| 2674 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2675 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2676 | } |
| 2677 | vlanOpTable := []byte{0x08, 0x03, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2678 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 2679 | |
| 2680 | request := &GetNextResponse{ |
| 2681 | MeBasePacket: MeBasePacket{ |
| 2682 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 2683 | EntityInstance: uint16(0x0202), |
| 2684 | }, |
| 2685 | Result: me.Success, |
| 2686 | AttributeMask: uint16(0x0400), |
| 2687 | Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": vlanOpTable}, |
| 2688 | } |
| 2689 | // Test serialization back to former string |
| 2690 | var options gopacket.SerializeOptions |
| 2691 | options.FixLengths = true |
| 2692 | |
| 2693 | buffer := gopacket.NewSerializeBuffer() |
| 2694 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2695 | assert.NoError(t, err) |
| 2696 | |
| 2697 | outgoingPacket := buffer.Bytes() |
| 2698 | reconstituted := packetToString(outgoingPacket) |
| 2699 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2700 | } |
| 2701 | |
| 2702 | // TODO: Create request/response tests for all of the following types//GetCurrentData, |
| 2703 | //SetTable} |
| 2704 | |
| 2705 | func TestAlarmNotificationDecode(t *testing.T) { |
| 2706 | goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2707 | data, err := stringToPacket(goodMessage) |
| 2708 | assert.NoError(t, err) |
| 2709 | |
| 2710 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2711 | assert.NotNil(t, packet) |
| 2712 | |
| 2713 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2714 | assert.NotNil(t, packet) |
| 2715 | |
| 2716 | omciMsg, ok := omciLayer.(*OMCI) |
| 2717 | assert.True(t, ok) |
| 2718 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2719 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2720 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2721 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2722 | |
| 2723 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2724 | assert.NotNil(t, msgLayer) |
| 2725 | |
| 2726 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2727 | assert.True(t, ok2) |
| 2728 | assert.NotNil(t, request) |
| 2729 | assert.Equal(t, request.EntityClass, me.PhysicalPathTerminationPointEthernetUniClassID) |
| 2730 | assert.Equal(t, request.EntityInstance, uint16(0x104)) |
| 2731 | assert.Equal(t, request.AlarmBitmap, [28]byte{ |
| 2732 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2733 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2734 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2735 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2736 | }) |
| 2737 | assert.Equal(t, request.AlarmSequenceNumber, byte(5)) |
| 2738 | |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 2739 | // Active/Clear tests |
| 2740 | active, err2 := request.IsAlarmActive(0) |
| 2741 | clear, err3 := request.IsAlarmClear(0) |
| 2742 | assert.Nil(t, err2) |
| 2743 | assert.Nil(t, err3) |
| 2744 | assert.True(t, active) |
| 2745 | assert.False(t, clear) |
| 2746 | |
| 2747 | // Active/Clear for undefined alarm bits |
| 2748 | active, err2 = request.IsAlarmActive(1) |
| 2749 | clear, err3 = request.IsAlarmClear(1) |
| 2750 | assert.NotNil(t, err2) |
| 2751 | assert.NotNil(t, err3) |
| 2752 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2753 | // Verify string output for message |
| 2754 | packetString := packet.String() |
| 2755 | assert.NotZero(t, len(packetString)) |
| 2756 | } |
| 2757 | |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 2758 | func TestInvalidClassAlarmNotificationDecode(t *testing.T) { |
| 2759 | // Choosing GalEthernetProfile (272) since it does not support alarms, show we should |
| 2760 | // file the decode |
| 2761 | badMessage := "0000100a01100104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2762 | data, err := stringToPacket(badMessage) |
| 2763 | assert.NoError(t, err) |
| 2764 | |
| 2765 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2766 | assert.NotNil(t, packet) |
| 2767 | |
| 2768 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2769 | assert.NotNil(t, packet) |
| 2770 | |
| 2771 | omciMsg, ok := omciLayer.(*OMCI) |
| 2772 | assert.True(t, ok) |
| 2773 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2774 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2775 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2776 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2777 | |
| 2778 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2779 | assert.Nil(t, msgLayer) |
| 2780 | |
| 2781 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2782 | assert.False(t, ok2) |
| 2783 | assert.Nil(t, request) |
| 2784 | } |
| 2785 | |
| 2786 | func TestUnknownsMeAlarmNotificationDecode(t *testing.T) { |
| 2787 | // Choosing class ID 22 since it is in the G.988 class ID space and is reserved |
| 2788 | goodMessage := "0000100a00160104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2789 | data, err := stringToPacket(goodMessage) |
| 2790 | assert.NoError(t, err) |
| 2791 | |
| 2792 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2793 | assert.NotNil(t, packet) |
| 2794 | |
| 2795 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2796 | assert.NotNil(t, packet) |
| 2797 | |
| 2798 | omciMsg, ok := omciLayer.(*OMCI) |
| 2799 | assert.True(t, ok) |
| 2800 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2801 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2802 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2803 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2804 | |
| 2805 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2806 | assert.NotNil(t, msgLayer) |
| 2807 | |
| 2808 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2809 | assert.True(t, ok2) |
| 2810 | assert.NotNil(t, request) |
| 2811 | assert.Equal(t, request.EntityClass, me.ClassID(22)) |
| 2812 | assert.Equal(t, request.EntityInstance, uint16(0x104)) |
| 2813 | assert.Equal(t, request.AlarmBitmap, [28]byte{ |
| 2814 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2815 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2816 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2817 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2818 | }) |
| 2819 | assert.Equal(t, request.AlarmSequenceNumber, byte(5)) |
| 2820 | } |
| 2821 | |
| 2822 | func TestVendorSpecificAlarmNotificationDecode(t *testing.T) { |
| 2823 | // Choosing class ID 255 since it is in the first vendor specific class ID space |
| 2824 | goodMessage := "0000100a00FF0104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2825 | data, err := stringToPacket(goodMessage) |
| 2826 | assert.NoError(t, err) |
| 2827 | |
| 2828 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2829 | assert.NotNil(t, packet) |
| 2830 | |
| 2831 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2832 | assert.NotNil(t, packet) |
| 2833 | |
| 2834 | omciMsg, ok := omciLayer.(*OMCI) |
| 2835 | assert.True(t, ok) |
| 2836 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2837 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2838 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2839 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2840 | |
| 2841 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2842 | assert.NotNil(t, msgLayer) |
| 2843 | |
| 2844 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2845 | assert.True(t, ok2) |
| 2846 | assert.NotNil(t, request) |
| 2847 | assert.Equal(t, request.EntityClass, me.ClassID(255)) |
| 2848 | assert.Equal(t, request.EntityInstance, uint16(0x104)) |
| 2849 | assert.Equal(t, request.AlarmBitmap, [28]byte{ |
| 2850 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2851 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2852 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2853 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2854 | }) |
| 2855 | assert.Equal(t, request.AlarmSequenceNumber, byte(5)) |
| 2856 | } |
| 2857 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2858 | func TestAlarmNotificationSerialize(t *testing.T) { |
| 2859 | goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2860 | |
| 2861 | omciLayer := &OMCI{ |
| 2862 | TransactionID: 0, |
| 2863 | MessageType: AlarmNotificationType, |
| 2864 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2865 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2866 | } |
| 2867 | request := &AlarmNotificationMsg{ |
| 2868 | MeBasePacket: MeBasePacket{ |
| 2869 | EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 2870 | EntityInstance: uint16(0x104), |
| 2871 | }, |
| 2872 | AlarmBitmap: [28]byte{ |
| 2873 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2874 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2875 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2876 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2877 | }, |
| 2878 | AlarmSequenceNumber: byte(5), |
| 2879 | } |
| 2880 | // Test serialization back to former string |
| 2881 | var options gopacket.SerializeOptions |
| 2882 | options.FixLengths = true |
| 2883 | |
| 2884 | buffer := gopacket.NewSerializeBuffer() |
| 2885 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2886 | assert.NoError(t, err) |
| 2887 | |
| 2888 | outgoingPacket := buffer.Bytes() |
| 2889 | reconstituted := packetToString(outgoingPacket) |
| 2890 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2891 | } |
| 2892 | |
| 2893 | func TestAttributeValueChangeDecode(t *testing.T) { |
| 2894 | goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028" |
| 2895 | data, err := stringToPacket(goodMessage) |
| 2896 | assert.NoError(t, err) |
| 2897 | |
| 2898 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2899 | assert.NotNil(t, packet) |
| 2900 | |
| 2901 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2902 | assert.NotNil(t, packet) |
| 2903 | |
| 2904 | omciMsg, ok := omciLayer.(*OMCI) |
| 2905 | assert.True(t, ok) |
| 2906 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2907 | assert.Equal(t, omciMsg.MessageType, AttributeValueChangeType) |
| 2908 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2909 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2910 | |
| 2911 | msgLayer := packet.Layer(LayerTypeAttributeValueChange) |
| 2912 | assert.NotNil(t, msgLayer) |
| 2913 | |
| 2914 | request, ok2 := msgLayer.(*AttributeValueChangeMsg) |
| 2915 | assert.True(t, ok2) |
| 2916 | assert.NotNil(t, request) |
| 2917 | assert.Equal(t, request.AttributeMask, uint16(0x8000)) |
| 2918 | assert.Equal(t, request.EntityClass, me.SoftwareImageClassID) |
| 2919 | assert.Equal(t, request.EntityInstance, uint16(0)) |
| 2920 | assert.Equal(t, request.Attributes["Version"], []byte{ |
| 2921 | 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36, |
| 2922 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) |
| 2923 | |
| 2924 | // Verify string output for message |
| 2925 | packetString := packet.String() |
| 2926 | assert.NotZero(t, len(packetString)) |
| 2927 | } |
| 2928 | |
| 2929 | func TestAttributeValueChangeSerialize(t *testing.T) { |
| 2930 | goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028" |
| 2931 | |
| 2932 | omciLayer := &OMCI{ |
| 2933 | TransactionID: 0, |
| 2934 | MessageType: AttributeValueChangeType, |
| 2935 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2936 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2937 | } |
| 2938 | request := &AttributeValueChangeMsg{ |
| 2939 | MeBasePacket: MeBasePacket{ |
| 2940 | EntityClass: me.SoftwareImageClassID, |
| 2941 | EntityInstance: uint16(0), |
| 2942 | }, |
| 2943 | AttributeMask: uint16(0x8000), |
| 2944 | Attributes: me.AttributeValueMap{ |
| 2945 | "Version": []byte{ |
| 2946 | 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36, |
| 2947 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2948 | }, |
| 2949 | }, |
| 2950 | } |
| 2951 | // Test serialization back to former string |
| 2952 | var options gopacket.SerializeOptions |
| 2953 | options.FixLengths = true |
| 2954 | |
| 2955 | buffer := gopacket.NewSerializeBuffer() |
| 2956 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2957 | assert.NoError(t, err) |
| 2958 | |
| 2959 | outgoingPacket := buffer.Bytes() |
| 2960 | reconstituted := packetToString(outgoingPacket) |
| 2961 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2962 | } |
| 2963 | |
Chip Boling | 4e0ac9a | 2021-01-20 14:23:09 -0600 | [diff] [blame] | 2964 | func TestJira3769(t *testing.T) { |
| 2965 | // VOL-3769. Error parsing get response with processing error and large mask |
| 2966 | sampleMessage := "035e290a0101000001FFFC000000000000000000000000000000000000000000000000000000000000000028" |
| 2967 | data, err := stringToPacket(sampleMessage) |
| 2968 | assert.NoError(t, err) |
| 2969 | |
| 2970 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2971 | assert.NotNil(t, packet) |
| 2972 | |
| 2973 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2974 | assert.NotNil(t, omciLayer) |
| 2975 | |
| 2976 | omciMsg, ok := omciLayer.(*OMCI) |
| 2977 | assert.True(t, ok) |
| 2978 | assert.Equal(t, omciMsg.TransactionID, uint16(0x035e)) |
| 2979 | assert.Equal(t, omciMsg.MessageType, GetResponseType) |
| 2980 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2981 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2982 | |
| 2983 | // before bugfix for this JIRA, the following call returned 'nil' Failure was |
| 2984 | // occuring before this at during getResposne decoding. |
| 2985 | msgLayer := packet.Layer(LayerTypeGetResponse) |
| 2986 | assert.NotNil(t, msgLayer) |
| 2987 | |
| 2988 | response, ok2 := msgLayer.(*GetResponse) |
| 2989 | assert.True(t, ok2) |
| 2990 | assert.NotNil(t, response) |
| 2991 | assert.Equal(t, response.Result, me.ProcessingError) |
| 2992 | assert.Equal(t, response.AttributeMask, uint16(0xFFFC)) |
| 2993 | } |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 2994 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2995 | // TODO: Create notification tests for all of the following types |
| 2996 | //TestResult, |
Chip Boling | 2c046fa | 2021-02-23 11:30:29 -0600 | [diff] [blame] | 2997 | |
| 2998 | func TestJira3863(t *testing.T) { |
| 2999 | goodMessage := "81a9240a013880010700000000000000000000000000000000000000000000000000000000000000000000283f73ddea" |
| 3000 | data, err := stringToPacket(goodMessage) |
| 3001 | assert.NoError(t, err) |
| 3002 | |
| 3003 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3004 | assert.NotNil(t, packet) |
| 3005 | |
| 3006 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3007 | assert.NotNil(t, packet) |
| 3008 | |
| 3009 | omciMsg, ok := omciLayer.(*OMCI) |
| 3010 | assert.True(t, ok) |
| 3011 | assert.NotNil(t, omciMsg) |
| 3012 | |
| 3013 | msgLayer := packet.Layer(LayerTypeCreateResponse) |
| 3014 | assert.NotNil(t, msgLayer) |
| 3015 | |
| 3016 | // FEC PM ME not in class map so the following was failing (ok2 false) |
| 3017 | response, ok2 := msgLayer.(*CreateResponse) |
| 3018 | assert.True(t, ok2) |
| 3019 | assert.NotNil(t, response) |
| 3020 | |
| 3021 | // Verify string output for message |
| 3022 | packetString := packet.String() |
| 3023 | assert.NotZero(t, len(packetString)) |
| 3024 | } |