Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | package omci_test |
| 18 | |
| 19 | import ( |
| 20 | "encoding/base64" |
| 21 | "fmt" |
| 22 | . "github.com/cboling/omci" |
| 23 | me "github.com/cboling/omci/generated" |
| 24 | "github.com/google/gopacket" |
| 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, |
| 1486 | |
| 1487 | func TestStartSoftwareDownloadRequestDecode(t *testing.T) { |
| 1488 | // TODO: Need to complete implementation & debug this |
| 1489 | //goodMessage := "0000530a0007000113000f424001000100000000000000000000000000000000000000000000000000000028" |
| 1490 | //data, err := stringToPacket(goodMessage) |
| 1491 | //assert.NoError(t, err) |
| 1492 | // |
| 1493 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1494 | //assert.NotNil(t, packet) |
| 1495 | // |
| 1496 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1497 | //assert.NotNil(t, packet) |
| 1498 | // |
| 1499 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1500 | //assert.True(t, ok) |
| 1501 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1502 | //assert.Equal(t, omciMsg.MessageType, StartSoftwareDownloadRequestType) |
| 1503 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1504 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1505 | // |
| 1506 | //msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest) |
| 1507 | //assert.NotNil(t, msgLayer) |
| 1508 | // |
| 1509 | //request, ok2 := msgLayer.(*StartSoftwareDownloadRequest) |
| 1510 | //assert.True(t, ok2) |
| 1511 | //assert.NotNil(t, request) |
| 1512 | // |
| 1513 | //// Verify string output for message |
| 1514 | //packetString := packet.String() |
| 1515 | //assert.NotZero(t, len(packetString)) |
| 1516 | } |
| 1517 | |
| 1518 | func TestStartSoftwareDownloadRequestSerialize(t *testing.T) { |
| 1519 | //// TODO: Need to complete implementation & debug this |
| 1520 | //goodMessage := "0000530a0007000113000f424001000100000000000000000000000000000000000000000000000000000028" |
| 1521 | // |
| 1522 | //omciLayer := &OMCI{ |
| 1523 | // TransactionID: 0x01, |
| 1524 | // MessageType: StartSoftwareDownloadRequestType, |
| 1525 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1526 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1527 | //} |
| 1528 | //request := &StartSoftwareDownloadRequest{ |
| 1529 | // MeBasePacket: MeBasePacket{ |
| 1530 | // EntityClass: OnuDataClassID, |
| 1531 | // // Default Instance ID is 0 |
| 1532 | // }, |
| 1533 | //} |
| 1534 | //// Test serialization back to former string |
| 1535 | //var options gopacket.SerializeOptions |
| 1536 | //options.FixLengths = true |
| 1537 | // |
| 1538 | //buffer := gopacket.NewSerializeBuffer() |
| 1539 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1540 | //assert.NoError(t, err) |
| 1541 | // |
| 1542 | //outgoingPacket := buffer.Bytes() |
| 1543 | //reconstituted := packetToString(outgoingPacket) |
| 1544 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1545 | } |
| 1546 | |
| 1547 | func TestStartSoftwareDownloadResponseDecode(t *testing.T) { |
| 1548 | // TODO: Need to complete implementation & debug this |
| 1549 | //goodMessage := "" |
| 1550 | //data, err := stringToPacket(goodMessage) |
| 1551 | //assert.NoError(t, err) |
| 1552 | // |
| 1553 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1554 | //assert.NotNil(t, packet) |
| 1555 | // |
| 1556 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1557 | //assert.NotNil(t, packet) |
| 1558 | // |
| 1559 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1560 | //assert.True(t, ok) |
| 1561 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1562 | //assert.Equal(t, omciMsg.MessageType, StartSoftwareDownloadResponseType) |
| 1563 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1564 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1565 | // |
| 1566 | //msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadResponse) |
| 1567 | // |
| 1568 | //assert.NotNil(t, msgLayer) |
| 1569 | // |
| 1570 | //response, ok2 := msgLayer.(*StartSoftwareDownloadResponse) |
| 1571 | //assert.True(t, ok2) |
| 1572 | //assert.NotNil(t, response) |
| 1573 | // |
| 1574 | //// Verify string output for message |
| 1575 | //packetString := packet.String() |
| 1576 | //assert.NotZero(t, len(packetString)) |
| 1577 | } |
| 1578 | |
| 1579 | func TestStartSoftwareDownloadResponseSerialize(t *testing.T) { |
| 1580 | // TODO: Need to complete implementation & debug this |
| 1581 | //goodMessage := "" |
| 1582 | // |
| 1583 | //omciLayer := &OMCI{ |
| 1584 | // TransactionID: 0x01, |
| 1585 | // MessageType: StartSoftwareDownloadResponseType, |
| 1586 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1587 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1588 | //} |
| 1589 | //request := &StartSoftwareDownloadResponse{ |
| 1590 | // MeBasePacket: MeBasePacket{ |
| 1591 | // EntityClass: OnuDataClassID, |
| 1592 | // // Default Instance ID is 0 |
| 1593 | // }, |
| 1594 | //} |
| 1595 | //// Test serialization back to former string |
| 1596 | //var options gopacket.SerializeOptions |
| 1597 | //options.FixLengths = true |
| 1598 | // |
| 1599 | //buffer := gopacket.NewSerializeBuffer() |
| 1600 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1601 | //assert.NoError(t, err) |
| 1602 | // |
| 1603 | //outgoingPacket := buffer.Bytes() |
| 1604 | //reconstituted := packetToString(outgoingPacket) |
| 1605 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1606 | } |
| 1607 | |
| 1608 | func TestDownloadSectionRequestDecode(t *testing.T) { |
| 1609 | // TODO: Need to complete implementation & debug this |
| 1610 | //goodMessage := "0000140a00070001083534363836393733323036393733323036313230373436353733373400000000000028" |
| 1611 | //data, err := stringToPacket(goodMessage) |
| 1612 | //assert.NoError(t, err) |
| 1613 | // |
| 1614 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1615 | //assert.NotNil(t, packet) |
| 1616 | // |
| 1617 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1618 | //assert.NotNil(t, packet) |
| 1619 | // |
| 1620 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1621 | //assert.True(t, ok) |
| 1622 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1623 | //assert.Equal(t, omciMsg.MessageType, DownloadSectionRequestType) |
| 1624 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1625 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1626 | // |
| 1627 | //msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 1628 | //assert.NotNil(t, msgLayer) |
| 1629 | // |
| 1630 | //request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 1631 | //assert.True(t, ok2) |
| 1632 | //assert.NotNil(t, request) |
| 1633 | // |
| 1634 | //// Verify string output for message |
| 1635 | //packetString := packet.String() |
| 1636 | //assert.NotZero(t, len(packetString)) |
| 1637 | } |
| 1638 | |
| 1639 | func TestDownloadSectionRequestSerialize(t *testing.T) { |
| 1640 | // TODO: Need to complete implementation & debug this |
| 1641 | //goodMessage := "0000140a00070001083534363836393733323036393733323036313230373436353733373400000000000028" |
| 1642 | // |
| 1643 | //omciLayer := &OMCI{ |
| 1644 | // TransactionID: 0x01, |
| 1645 | // MessageType: DownloadSectionRequestType, |
| 1646 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1647 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1648 | //} |
| 1649 | //request := &DownloadSectionRequest{ |
| 1650 | // MeBasePacket: MeBasePacket{ |
| 1651 | // EntityClass: OnuDataClassID, |
| 1652 | // // Default Instance ID is 0 |
| 1653 | // }, |
| 1654 | //} |
| 1655 | //// Test serialization back to former string |
| 1656 | //var options gopacket.SerializeOptions |
| 1657 | //options.FixLengths = true |
| 1658 | // |
| 1659 | //buffer := gopacket.NewSerializeBuffer() |
| 1660 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1661 | //assert.NoError(t, err) |
| 1662 | // |
| 1663 | //outgoingPacket := buffer.Bytes() |
| 1664 | //reconstituted := packetToString(outgoingPacket) |
| 1665 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1666 | } |
| 1667 | |
| 1668 | func TestDownloadSectionResponseDecode(t *testing.T) { |
| 1669 | // TODO: Need to complete implementation & debug this |
| 1670 | //goodMessage := "" |
| 1671 | //data, err := stringToPacket(goodMessage) |
| 1672 | //assert.NoError(t, err) |
| 1673 | // |
| 1674 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1675 | //assert.NotNil(t, packet) |
| 1676 | // |
| 1677 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1678 | //assert.NotNil(t, packet) |
| 1679 | // |
| 1680 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1681 | //assert.True(t, ok) |
| 1682 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1683 | //assert.Equal(t, omciMsg.MessageType, DownloadSectionResponseType) |
| 1684 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1685 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1686 | // |
| 1687 | //msgLayer := packet.Layer(LayerTypeDownloadSectionResponse) |
| 1688 | // |
| 1689 | //assert.NotNil(t, msgLayer) |
| 1690 | // |
| 1691 | //response, ok2 := msgLayer.(*DownloadSectionResponse) |
| 1692 | //assert.True(t, ok2) |
| 1693 | //assert.NotNil(t, response) |
| 1694 | // |
| 1695 | //// Verify string output for message |
| 1696 | //packetString := packet.String() |
| 1697 | //assert.NotZero(t, len(packetString)) |
| 1698 | } |
| 1699 | |
| 1700 | func TestDownloadSectionResponseSerialize(t *testing.T) { |
| 1701 | // TODO: Need to complete implementation & debug this |
| 1702 | //goodMessage := "" |
| 1703 | // |
| 1704 | //omciLayer := &OMCI{ |
| 1705 | // TransactionID: 0x01, |
| 1706 | // MessageType: DownloadSectionResponseType, |
| 1707 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1708 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1709 | //} |
| 1710 | //request := &DownloadSectionResponse{ |
| 1711 | // MeBasePacket: MeBasePacket{ |
| 1712 | // EntityClass: OnuDataClassID, |
| 1713 | // // Default Instance ID is 0 |
| 1714 | // }, |
| 1715 | //} |
| 1716 | //// Test serialization back to former string |
| 1717 | //var options gopacket.SerializeOptions |
| 1718 | //options.FixLengths = true |
| 1719 | // |
| 1720 | //buffer := gopacket.NewSerializeBuffer() |
| 1721 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1722 | //assert.NoError(t, err) |
| 1723 | // |
| 1724 | //outgoingPacket := buffer.Bytes() |
| 1725 | //reconstituted := packetToString(outgoingPacket) |
| 1726 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1727 | } |
| 1728 | |
| 1729 | func TestEndSoftwareDownloadRequestDecode(t *testing.T) { |
| 1730 | // TODO: Need to complete implementation & debug this |
| 1731 | //goodMessage := "0000550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028" |
| 1732 | //data, err := stringToPacket(goodMessage) |
| 1733 | //assert.NoError(t, err) |
| 1734 | // |
| 1735 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1736 | //assert.NotNil(t, packet) |
| 1737 | // |
| 1738 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1739 | //assert.NotNil(t, packet) |
| 1740 | // |
| 1741 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1742 | //assert.True(t, ok) |
| 1743 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1744 | //assert.Equal(t, omciMsg.MessageType, EndSoftwareDownloadRequestType) |
| 1745 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1746 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1747 | // |
| 1748 | //msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadRequest) |
| 1749 | //assert.NotNil(t, msgLayer) |
| 1750 | // |
| 1751 | //request, ok2 := msgLayer.(*EndSoftwareDownloadRequest) |
| 1752 | //assert.True(t, ok2) |
| 1753 | //assert.NotNil(t, request) |
| 1754 | // |
| 1755 | //// Verify string output for message |
| 1756 | //packetString := packet.String() |
| 1757 | //assert.NotZero(t, len(packetString)) |
| 1758 | } |
| 1759 | |
| 1760 | func TestEndSoftwareDownloadRequestSerialize(t *testing.T) { |
| 1761 | // TODO: Need to complete implementation & debug this |
| 1762 | //goodMessage := "0000550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028" |
| 1763 | // |
| 1764 | //omciLayer := &OMCI{ |
| 1765 | // TransactionID: 0x01, |
| 1766 | // MessageType: EndSoftwareDownloadRequestType, |
| 1767 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1768 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1769 | //} |
| 1770 | //request := &EndSoftwareDownloadRequest{ |
| 1771 | // MeBasePacket: MeBasePacket{ |
| 1772 | // EntityClass: OnuDataClassID, |
| 1773 | // // Default Instance ID is 0 |
| 1774 | // }, |
| 1775 | //} |
| 1776 | //// Test serialization back to former string |
| 1777 | //var options gopacket.SerializeOptions |
| 1778 | //options.FixLengths = true |
| 1779 | // |
| 1780 | //buffer := gopacket.NewSerializeBuffer() |
| 1781 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1782 | //assert.NoError(t, err) |
| 1783 | // |
| 1784 | //outgoingPacket := buffer.Bytes() |
| 1785 | //reconstituted := packetToString(outgoingPacket) |
| 1786 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1787 | } |
| 1788 | |
| 1789 | func TestEndSoftwareDownloadResponseDecode(t *testing.T) { |
| 1790 | // TODO: Need to complete implementation & debug this |
| 1791 | //goodMessage := "" |
| 1792 | //data, err := stringToPacket(goodMessage) |
| 1793 | //assert.NoError(t, err) |
| 1794 | // |
| 1795 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1796 | //assert.NotNil(t, packet) |
| 1797 | // |
| 1798 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1799 | //assert.NotNil(t, packet) |
| 1800 | // |
| 1801 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1802 | //assert.True(t, ok) |
| 1803 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1804 | //assert.Equal(t, omciMsg.MessageType, EndSoftwareDownloadResponseType) |
| 1805 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1806 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1807 | // |
| 1808 | //msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadResponse) |
| 1809 | // |
| 1810 | //assert.NotNil(t, msgLayer) |
| 1811 | // |
| 1812 | //response, ok2 := msgLayer.(*EndSoftwareDownloadResponse) |
| 1813 | //assert.True(t, ok2) |
| 1814 | //assert.NotNil(t, response) |
| 1815 | // |
| 1816 | //// Verify string output for message |
| 1817 | //packetString := packet.String() |
| 1818 | //assert.NotZero(t, len(packetString)) |
| 1819 | } |
| 1820 | |
| 1821 | func TestEndSoftwareDownloadResponseSerialize(t *testing.T) { |
| 1822 | // TODO: Need to complete implementation & debug this |
| 1823 | //goodMessage := "" |
| 1824 | // |
| 1825 | //omciLayer := &OMCI{ |
| 1826 | // TransactionID: 0x01, |
| 1827 | // MessageType: EndSoftwareDownloadResponseType, |
| 1828 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1829 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1830 | //} |
| 1831 | //request := &EndSoftwareDownloadResponse{ |
| 1832 | // MeBasePacket: MeBasePacket{ |
| 1833 | // EntityClass: OnuDataClassID, |
| 1834 | // // Default Instance ID is 0 |
| 1835 | // }, |
| 1836 | //} |
| 1837 | //// Test serialization back to former string |
| 1838 | //var options gopacket.SerializeOptions |
| 1839 | //options.FixLengths = true |
| 1840 | // |
| 1841 | //buffer := gopacket.NewSerializeBuffer() |
| 1842 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1843 | //assert.NoError(t, err) |
| 1844 | // |
| 1845 | //outgoingPacket := buffer.Bytes() |
| 1846 | //reconstituted := packetToString(outgoingPacket) |
| 1847 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1848 | } |
| 1849 | |
| 1850 | func TestActivateSoftwareRequestDecode(t *testing.T) { |
| 1851 | // TODO: Need to complete implementation & debug this |
| 1852 | //goodMessage := "0000560a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1853 | //data, err := stringToPacket(goodMessage) |
| 1854 | //assert.NoError(t, err) |
| 1855 | // |
| 1856 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1857 | //assert.NotNil(t, packet) |
| 1858 | // |
| 1859 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1860 | //assert.NotNil(t, packet) |
| 1861 | // |
| 1862 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1863 | //assert.True(t, ok) |
| 1864 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1865 | //assert.Equal(t, omciMsg.MessageType, ActivateSoftwareRequestType) |
| 1866 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1867 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1868 | // |
| 1869 | //msgLayer := packet.Layer(LayerTypeActivateSoftwareRequest) |
| 1870 | //assert.NotNil(t, msgLayer) |
| 1871 | // |
| 1872 | //request, ok2 := msgLayer.(*ActivateSoftwareRequest) |
| 1873 | //assert.True(t, ok2) |
| 1874 | //assert.NotNil(t, request) |
| 1875 | // |
| 1876 | //// Verify string output for message |
| 1877 | //packetString := packet.String() |
| 1878 | //assert.NotZero(t, len(packetString)) |
| 1879 | } |
| 1880 | |
| 1881 | func TestActivateSoftwareRequestSerialize(t *testing.T) { |
| 1882 | // TODO: Need to complete implementation & debug this |
| 1883 | //goodMessage := "0000560a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1884 | // |
| 1885 | //omciLayer := &OMCI{ |
| 1886 | // TransactionID: 0x01, |
| 1887 | // MessageType: ActivateSoftwareRequestType, |
| 1888 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1889 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1890 | //} |
| 1891 | //request := &ActivateSoftwareRequest{ |
| 1892 | // MeBasePacket: MeBasePacket{ |
| 1893 | // EntityClass: OnuDataClassID, |
| 1894 | // // Default Instance ID is 0 |
| 1895 | // }, |
| 1896 | //} |
| 1897 | //// Test serialization back to former string |
| 1898 | //var options gopacket.SerializeOptions |
| 1899 | //options.FixLengths = true |
| 1900 | // |
| 1901 | //buffer := gopacket.NewSerializeBuffer() |
| 1902 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1903 | //assert.NoError(t, err) |
| 1904 | // |
| 1905 | //outgoingPacket := buffer.Bytes() |
| 1906 | //reconstituted := packetToString(outgoingPacket) |
| 1907 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1908 | } |
| 1909 | |
| 1910 | func TestActivateSoftwareResponseDecode(t *testing.T) { |
| 1911 | // TODO: Need to complete implementation & debug this |
| 1912 | //goodMessage := "" |
| 1913 | //data, err := stringToPacket(goodMessage) |
| 1914 | //assert.NoError(t, err) |
| 1915 | // |
| 1916 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1917 | //assert.NotNil(t, packet) |
| 1918 | // |
| 1919 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1920 | //assert.NotNil(t, packet) |
| 1921 | // |
| 1922 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1923 | //assert.True(t, ok) |
| 1924 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1925 | //assert.Equal(t, omciMsg.MessageType, ActivateSoftwareResponseType) |
| 1926 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1927 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1928 | // |
| 1929 | //msgLayer := packet.Layer(LayerTypeActivateSoftwareResponse) |
| 1930 | // |
| 1931 | //assert.NotNil(t, msgLayer) |
| 1932 | // |
| 1933 | //response, ok2 := msgLayer.(*ActivateSoftwareResponse) |
| 1934 | //assert.True(t, ok2) |
| 1935 | //assert.NotNil(t, response) |
| 1936 | // |
| 1937 | //// Verify string output for message |
| 1938 | //packetString := packet.String() |
| 1939 | //assert.NotZero(t, len(packetString)) |
| 1940 | } |
| 1941 | |
| 1942 | func TestActivateSoftwareResponseSerialize(t *testing.T) { |
| 1943 | // TODO: Need to complete implementation & debug this |
| 1944 | //goodMessage := "" |
| 1945 | // |
| 1946 | //omciLayer := &OMCI{ |
| 1947 | // TransactionID: 0x01, |
| 1948 | // MessageType: ActivateSoftwareResponseType, |
| 1949 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1950 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1951 | //} |
| 1952 | //request := &ActivateSoftwareResponse{ |
| 1953 | // MeBasePacket: MeBasePacket{ |
| 1954 | // EntityClass: OnuDataClassID, |
| 1955 | // // Default Instance ID is 0 |
| 1956 | // }, |
| 1957 | //} |
| 1958 | //// Test serialization back to former string |
| 1959 | //var options gopacket.SerializeOptions |
| 1960 | //options.FixLengths = true |
| 1961 | // |
| 1962 | //buffer := gopacket.NewSerializeBuffer() |
| 1963 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1964 | //assert.NoError(t, err) |
| 1965 | // |
| 1966 | //outgoingPacket := buffer.Bytes() |
| 1967 | //reconstituted := packetToString(outgoingPacket) |
| 1968 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1969 | } |
| 1970 | |
| 1971 | func TestCommitSoftwareRequestDecode(t *testing.T) { |
| 1972 | // TODO: Need to complete implementation & debug this |
| 1973 | //goodMessage := "0000570a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1974 | //data, err := stringToPacket(goodMessage) |
| 1975 | //assert.NoError(t, err) |
| 1976 | // |
| 1977 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1978 | //assert.NotNil(t, packet) |
| 1979 | // |
| 1980 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 1981 | //assert.NotNil(t, packet) |
| 1982 | // |
| 1983 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1984 | //assert.True(t, ok) |
| 1985 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1986 | //assert.Equal(t, omciMsg.MessageType, CommitSoftwareRequestType) |
| 1987 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1988 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1989 | // |
| 1990 | //msgLayer := packet.Layer(LayerTypeCommitSoftwareRequest) |
| 1991 | //assert.NotNil(t, msgLayer) |
| 1992 | // |
| 1993 | //request, ok2 := msgLayer.(*CommitSoftwareRequest) |
| 1994 | //assert.True(t, ok2) |
| 1995 | //assert.NotNil(t, request) |
| 1996 | // |
| 1997 | //// Verify string output for message |
| 1998 | //packetString := packet.String() |
| 1999 | //assert.NotZero(t, len(packetString)) |
| 2000 | } |
| 2001 | |
| 2002 | func TestCommitSoftwareRequestSerialize(t *testing.T) { |
| 2003 | // TODO: Need to complete implementation & debug this |
| 2004 | //goodMessage := "0000570a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2005 | // |
| 2006 | //omciLayer := &OMCI{ |
| 2007 | // TransactionID: 0x01, |
| 2008 | // MessageType: CommitSoftwareRequestType, |
| 2009 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2010 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 2011 | //} |
| 2012 | //request := &CommitSoftwareRequest{ |
| 2013 | // MeBasePacket: MeBasePacket{ |
| 2014 | // EntityClass: OnuDataClassID, |
| 2015 | // // Default Instance ID is 0 |
| 2016 | // }, |
| 2017 | //} |
| 2018 | //// Test serialization back to former string |
| 2019 | //var options gopacket.SerializeOptions |
| 2020 | //options.FixLengths = true |
| 2021 | // |
| 2022 | //buffer := gopacket.NewSerializeBuffer() |
| 2023 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2024 | //assert.NoError(t, err) |
| 2025 | // |
| 2026 | //outgoingPacket := buffer.Bytes() |
| 2027 | //reconstituted := packetToString(outgoingPacket) |
| 2028 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2029 | } |
| 2030 | |
| 2031 | func TestCommitSoftwareResponseDecode(t *testing.T) { |
| 2032 | // TODO: Need to complete implementation & debug this |
| 2033 | //goodMessage := "" |
| 2034 | //data, err := stringToPacket(goodMessage) |
| 2035 | //assert.NoError(t, err) |
| 2036 | // |
| 2037 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2038 | //assert.NotNil(t, packet) |
| 2039 | // |
| 2040 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 2041 | //assert.NotNil(t, packet) |
| 2042 | // |
| 2043 | //omciMsg, ok := omciLayer.(*OMCI) |
| 2044 | //assert.True(t, ok) |
| 2045 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2046 | //assert.Equal(t, omciMsg.MessageType, CommitSoftwareResponseType) |
| 2047 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2048 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2049 | // |
| 2050 | //msgLayer := packet.Layer(LayerTypeCommitSoftwareResponse) |
| 2051 | // |
| 2052 | //assert.NotNil(t, msgLayer) |
| 2053 | // |
| 2054 | //response, ok2 := msgLayer.(*CommitSoftwareResponse) |
| 2055 | //assert.True(t, ok2) |
| 2056 | //assert.NotNil(t, response) |
| 2057 | // |
| 2058 | //// Verify string output for message |
| 2059 | //packetString := packet.String() |
| 2060 | //assert.NotZero(t, len(packetString)) |
| 2061 | } |
| 2062 | |
| 2063 | func TestCommitSoftwareResponseSerialize(t *testing.T) { |
| 2064 | // TODO: Need to complete implementation & debug this |
| 2065 | //goodMessage := "" |
| 2066 | // |
| 2067 | //omciLayer := &OMCI{ |
| 2068 | // TransactionID: 0x01, |
| 2069 | // MessageType: CommitSoftwareResponseType, |
| 2070 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2071 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 2072 | //} |
| 2073 | //request := &CommitSoftwareResponse{ |
| 2074 | // MeBasePacket: MeBasePacket{ |
| 2075 | // EntityClass: OnuDataClassID, |
| 2076 | // // Default Instance ID is 0 |
| 2077 | // }, |
| 2078 | //} |
| 2079 | //// Test serialization back to former string |
| 2080 | //var options gopacket.SerializeOptions |
| 2081 | //options.FixLengths = true |
| 2082 | // |
| 2083 | //buffer := gopacket.NewSerializeBuffer() |
| 2084 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2085 | //assert.NoError(t, err) |
| 2086 | // |
| 2087 | //outgoingPacket := buffer.Bytes() |
| 2088 | //reconstituted := packetToString(outgoingPacket) |
| 2089 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2090 | } |
| 2091 | |
| 2092 | func TestMibResetResponseDecode(t *testing.T) { |
| 2093 | goodMessage := "00012F0A00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2094 | data, err := stringToPacket(goodMessage) |
| 2095 | assert.NoError(t, err) |
| 2096 | |
| 2097 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2098 | assert.NotNil(t, packet) |
| 2099 | |
| 2100 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2101 | assert.NotNil(t, packet) |
| 2102 | |
| 2103 | omciMsg, ok := omciLayer.(*OMCI) |
| 2104 | assert.True(t, ok) |
| 2105 | assert.Equal(t, omciMsg.MessageType, MibResetResponseType) |
| 2106 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2107 | |
| 2108 | msgLayer := packet.Layer(LayerTypeMibResetResponse) |
| 2109 | |
| 2110 | assert.NotNil(t, msgLayer) |
| 2111 | |
| 2112 | response, ok2 := msgLayer.(*MibResetResponse) |
| 2113 | assert.True(t, ok2) |
| 2114 | assert.NotNil(t, response) |
| 2115 | |
| 2116 | // Verify string output for message |
| 2117 | packetString := packet.String() |
| 2118 | assert.NotZero(t, len(packetString)) |
| 2119 | } |
| 2120 | |
| 2121 | func TestMibResetResponseSerialize(t *testing.T) { |
| 2122 | goodMessage := "00012F0A00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2123 | |
| 2124 | omciLayer := &OMCI{ |
| 2125 | TransactionID: 0x01, |
| 2126 | MessageType: MibResetResponseType, |
| 2127 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2128 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2129 | } |
| 2130 | request := &MibResetResponse{ |
| 2131 | MeBasePacket: MeBasePacket{ |
| 2132 | EntityClass: me.OnuDataClassID, |
| 2133 | // Default Instance ID is 0 |
| 2134 | }, |
| 2135 | } |
| 2136 | // Test serialization back to former string |
| 2137 | var options gopacket.SerializeOptions |
| 2138 | options.FixLengths = true |
| 2139 | |
| 2140 | buffer := gopacket.NewSerializeBuffer() |
| 2141 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2142 | assert.NoError(t, err) |
| 2143 | |
| 2144 | outgoingPacket := buffer.Bytes() |
| 2145 | reconstituted := packetToString(outgoingPacket) |
| 2146 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2147 | } |
| 2148 | |
| 2149 | func TestSynchronizeTimeRequestDecode(t *testing.T) { |
| 2150 | goodMessage := "0109580a0100000007e20c0101301b0000000000000000000000000000000000000000000000000000000028" |
| 2151 | data, err := stringToPacket(goodMessage) |
| 2152 | assert.NoError(t, err) |
| 2153 | |
| 2154 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2155 | assert.NotNil(t, packet) |
| 2156 | |
| 2157 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2158 | assert.NotNil(t, packet) |
| 2159 | |
| 2160 | omciMsg, ok := omciLayer.(*OMCI) |
| 2161 | assert.True(t, ok) |
| 2162 | assert.Equal(t, omciMsg.MessageType, SynchronizeTimeRequestType) |
| 2163 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2164 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2165 | |
| 2166 | msgLayer := packet.Layer(LayerTypeSynchronizeTimeRequest) |
| 2167 | assert.NotNil(t, msgLayer) |
| 2168 | |
| 2169 | request, ok2 := msgLayer.(*SynchronizeTimeRequest) |
| 2170 | assert.True(t, ok2) |
| 2171 | assert.NotNil(t, request) |
| 2172 | assert.Equal(t, request.Year, uint16(2018)) |
| 2173 | assert.Equal(t, request.Month, uint8(12)) |
| 2174 | assert.Equal(t, request.Day, uint8(1)) |
| 2175 | assert.Equal(t, request.Hour, uint8(01)) |
| 2176 | assert.Equal(t, request.Minute, uint8(48)) |
| 2177 | assert.Equal(t, request.Second, uint8(27)) |
| 2178 | |
| 2179 | // Verify string output for message |
| 2180 | packetString := packet.String() |
| 2181 | assert.NotZero(t, len(packetString)) |
| 2182 | } |
| 2183 | |
| 2184 | func TestSynchronizeTimeRequestSerialize(t *testing.T) { |
| 2185 | goodMessage := "0109580a0100000007e20c0101301b0000000000000000000000000000000000000000000000000000000028" |
| 2186 | |
| 2187 | omciLayer := &OMCI{ |
| 2188 | TransactionID: 0x0109, |
| 2189 | MessageType: SynchronizeTimeRequestType, |
| 2190 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2191 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2192 | } |
| 2193 | request := &SynchronizeTimeRequest{ |
| 2194 | MeBasePacket: MeBasePacket{ |
| 2195 | EntityClass: me.OnuGClassID, |
| 2196 | // Default Instance ID is 0 |
| 2197 | }, |
| 2198 | Year: uint16(2018), |
| 2199 | Month: uint8(12), |
| 2200 | Day: uint8(1), |
| 2201 | Hour: uint8(01), |
| 2202 | Minute: uint8(48), |
| 2203 | Second: uint8(27), |
| 2204 | } |
| 2205 | // Test serialization back to former string |
| 2206 | var options gopacket.SerializeOptions |
| 2207 | options.FixLengths = true |
| 2208 | |
| 2209 | buffer := gopacket.NewSerializeBuffer() |
| 2210 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2211 | assert.NoError(t, err) |
| 2212 | |
| 2213 | outgoingPacket := buffer.Bytes() |
| 2214 | reconstituted := packetToString(outgoingPacket) |
| 2215 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2216 | } |
| 2217 | |
| 2218 | func TestSynchronizeTimeResponseDecode(t *testing.T) { |
| 2219 | goodMessage := "0109380a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2220 | data, err := stringToPacket(goodMessage) |
| 2221 | assert.NoError(t, err) |
| 2222 | |
| 2223 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2224 | assert.NotNil(t, packet) |
| 2225 | |
| 2226 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2227 | assert.NotNil(t, packet) |
| 2228 | |
| 2229 | omciMsg, ok := omciLayer.(*OMCI) |
| 2230 | assert.True(t, ok) |
| 2231 | assert.Equal(t, omciMsg.MessageType, SynchronizeTimeResponseType) |
| 2232 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2233 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2234 | |
| 2235 | msgLayer := packet.Layer(LayerTypeSynchronizeTimeResponse) |
| 2236 | assert.NotNil(t, msgLayer) |
| 2237 | |
| 2238 | response, ok2 := msgLayer.(*SynchronizeTimeResponse) |
| 2239 | assert.True(t, ok2) |
| 2240 | assert.NotNil(t, response) |
| 2241 | |
| 2242 | // Verify string output for message |
| 2243 | packetString := packet.String() |
| 2244 | assert.NotZero(t, len(packetString)) |
| 2245 | } |
| 2246 | |
| 2247 | func TestSynchronizeTimeResponseSerialize(t *testing.T) { |
| 2248 | goodMessage := "0109380a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2249 | |
| 2250 | omciLayer := &OMCI{ |
| 2251 | TransactionID: 0x0109, |
| 2252 | MessageType: SynchronizeTimeResponseType, |
| 2253 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2254 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2255 | } |
| 2256 | request := &SynchronizeTimeResponse{ |
| 2257 | MeBasePacket: MeBasePacket{ |
| 2258 | EntityClass: me.OnuGClassID, |
| 2259 | EntityInstance: uint16(0), |
| 2260 | }, |
| 2261 | Result: me.Success, |
| 2262 | SuccessResults: uint8(0), |
| 2263 | } |
| 2264 | // Test serialization back to former string |
| 2265 | var options gopacket.SerializeOptions |
| 2266 | options.FixLengths = true |
| 2267 | |
| 2268 | buffer := gopacket.NewSerializeBuffer() |
| 2269 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2270 | assert.NoError(t, err) |
| 2271 | |
| 2272 | outgoingPacket := buffer.Bytes() |
| 2273 | reconstituted := packetToString(outgoingPacket) |
| 2274 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2275 | } |
| 2276 | |
| 2277 | func TestRebootRequestDecode(t *testing.T) { |
| 2278 | goodMessage := "0001590a01000000010000000000000000000000000000000000000000000000000000000000000000000028" |
| 2279 | data, err := stringToPacket(goodMessage) |
| 2280 | assert.NoError(t, err) |
| 2281 | |
| 2282 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2283 | assert.NotNil(t, packet) |
| 2284 | |
| 2285 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2286 | assert.NotNil(t, packet) |
| 2287 | |
| 2288 | omciMsg, ok := omciLayer.(*OMCI) |
| 2289 | assert.True(t, ok) |
| 2290 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0001)) |
| 2291 | assert.Equal(t, omciMsg.MessageType, RebootRequestType) |
| 2292 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2293 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2294 | |
| 2295 | msgLayer := packet.Layer(LayerTypeRebootRequest) |
| 2296 | assert.NotNil(t, msgLayer) |
| 2297 | |
| 2298 | request, ok2 := msgLayer.(*RebootRequest) |
| 2299 | assert.True(t, ok2) |
| 2300 | assert.NotNil(t, request) |
| 2301 | assert.Equal(t, request.EntityClass, me.OnuGClassID) |
| 2302 | assert.Equal(t, request.EntityInstance, uint16(0)) |
| 2303 | assert.Equal(t, request.RebootCondition, uint8(1)) |
| 2304 | |
| 2305 | // Verify string output for message |
| 2306 | packetString := packet.String() |
| 2307 | assert.NotZero(t, len(packetString)) |
| 2308 | } |
| 2309 | |
| 2310 | func TestRebootRequestSerialize(t *testing.T) { |
| 2311 | goodMessage := "0001590a01000000020000000000000000000000000000000000000000000000000000000000000000000028" |
| 2312 | |
| 2313 | omciLayer := &OMCI{ |
| 2314 | TransactionID: 0x0001, |
| 2315 | MessageType: RebootRequestType, |
| 2316 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2317 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2318 | } |
| 2319 | request := &RebootRequest{ |
| 2320 | MeBasePacket: MeBasePacket{ |
| 2321 | EntityClass: me.OnuGClassID, |
| 2322 | // Default Instance ID is 0 |
| 2323 | }, |
| 2324 | RebootCondition: uint8(2), |
| 2325 | } |
| 2326 | // Test serialization back to former string |
| 2327 | var options gopacket.SerializeOptions |
| 2328 | options.FixLengths = true |
| 2329 | |
| 2330 | buffer := gopacket.NewSerializeBuffer() |
| 2331 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2332 | assert.NoError(t, err) |
| 2333 | |
| 2334 | outgoingPacket := buffer.Bytes() |
| 2335 | reconstituted := packetToString(outgoingPacket) |
| 2336 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2337 | } |
| 2338 | |
| 2339 | func TestRebootResponseDecode(t *testing.T) { |
| 2340 | goodMessage := "023c390a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2341 | data, err := stringToPacket(goodMessage) |
| 2342 | assert.NoError(t, err) |
| 2343 | |
| 2344 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2345 | assert.NotNil(t, packet) |
| 2346 | |
| 2347 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2348 | assert.NotNil(t, packet) |
| 2349 | |
| 2350 | omciMsg, ok := omciLayer.(*OMCI) |
| 2351 | assert.True(t, ok) |
| 2352 | assert.Equal(t, omciMsg.TransactionID, uint16(0x023c)) |
| 2353 | assert.Equal(t, omciMsg.MessageType, RebootResponseType) |
| 2354 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2355 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2356 | |
| 2357 | msgLayer := packet.Layer(LayerTypeRebootResponse) |
| 2358 | assert.NotNil(t, msgLayer) |
| 2359 | |
| 2360 | response, ok2 := msgLayer.(*RebootResponse) |
| 2361 | assert.True(t, ok2) |
| 2362 | assert.NotNil(t, response) |
| 2363 | assert.Equal(t, response.EntityClass, me.OnuGClassID) |
| 2364 | assert.Equal(t, response.EntityInstance, uint16(0)) |
| 2365 | assert.Equal(t, response.Result, me.Success) |
| 2366 | |
| 2367 | // Verify string output for message |
| 2368 | packetString := packet.String() |
| 2369 | assert.NotZero(t, len(packetString)) |
| 2370 | } |
| 2371 | |
| 2372 | func TestRebootResponseSerialize(t *testing.T) { |
| 2373 | goodMessage := "023c390a01000000060000000000000000000000000000000000000000000000000000000000000000000028" |
| 2374 | |
| 2375 | omciLayer := &OMCI{ |
| 2376 | TransactionID: 0x023c, |
| 2377 | MessageType: RebootResponseType, |
| 2378 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2379 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2380 | } |
| 2381 | request := &RebootResponse{ |
| 2382 | MeBasePacket: MeBasePacket{ |
| 2383 | EntityClass: me.OnuGClassID, |
| 2384 | EntityInstance: uint16(0), |
| 2385 | }, |
| 2386 | Result: me.DeviceBusy, |
| 2387 | } |
| 2388 | // Test serialization back to former string |
| 2389 | var options gopacket.SerializeOptions |
| 2390 | options.FixLengths = true |
| 2391 | |
| 2392 | buffer := gopacket.NewSerializeBuffer() |
| 2393 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2394 | assert.NoError(t, err) |
| 2395 | |
| 2396 | outgoingPacket := buffer.Bytes() |
| 2397 | reconstituted := packetToString(outgoingPacket) |
| 2398 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2399 | } |
| 2400 | |
| 2401 | func TestGetNextRequestDecode(t *testing.T) { |
| 2402 | goodMessage := "285e5a0a00ab0202040000010000000000000000000000000000000000000000000000000000000000000028" |
| 2403 | data, err := stringToPacket(goodMessage) |
| 2404 | assert.NoError(t, err) |
| 2405 | |
| 2406 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2407 | assert.NotNil(t, packet) |
| 2408 | |
| 2409 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2410 | assert.NotNil(t, packet) |
| 2411 | |
| 2412 | omciMsg, ok := omciLayer.(*OMCI) |
| 2413 | assert.True(t, ok) |
| 2414 | assert.Equal(t, omciMsg.TransactionID, uint16(0x285e)) |
| 2415 | assert.Equal(t, omciMsg.MessageType, GetNextRequestType) |
| 2416 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2417 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2418 | |
| 2419 | msgLayer := packet.Layer(LayerTypeGetNextRequest) |
| 2420 | assert.NotNil(t, msgLayer) |
| 2421 | |
| 2422 | request, ok2 := msgLayer.(*GetNextRequest) |
| 2423 | assert.True(t, ok2) |
| 2424 | assert.NotNil(t, request) |
| 2425 | assert.Equal(t, request.EntityClass, me.ExtendedVlanTaggingOperationConfigurationDataClassID) |
| 2426 | assert.Equal(t, request.EntityInstance, uint16(0x0202)) |
| 2427 | assert.Equal(t, request.AttributeMask, uint16(0x0400)) |
| 2428 | assert.Equal(t, request.SequenceNumber, uint16(1)) |
| 2429 | |
| 2430 | // Verify string output for message |
| 2431 | packetString := packet.String() |
| 2432 | assert.NotZero(t, len(packetString)) |
| 2433 | } |
| 2434 | |
| 2435 | func TestGetNextRequestSerialize(t *testing.T) { |
| 2436 | goodMessage := "285e5a0a00ab0202040000010000000000000000000000000000000000000000000000000000000000000028" |
| 2437 | |
| 2438 | omciLayer := &OMCI{ |
| 2439 | TransactionID: 0x285e, |
| 2440 | MessageType: GetNextRequestType, |
| 2441 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2442 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2443 | } |
| 2444 | request := &GetNextRequest{ |
| 2445 | MeBasePacket: MeBasePacket{ |
| 2446 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 2447 | EntityInstance: uint16(0x0202), |
| 2448 | }, |
| 2449 | AttributeMask: uint16(0x0400), |
| 2450 | SequenceNumber: uint16(1), |
| 2451 | } |
| 2452 | // Test serialization back to former string |
| 2453 | var options gopacket.SerializeOptions |
| 2454 | options.FixLengths = true |
| 2455 | |
| 2456 | buffer := gopacket.NewSerializeBuffer() |
| 2457 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2458 | assert.NoError(t, err) |
| 2459 | |
| 2460 | outgoingPacket := buffer.Bytes() |
| 2461 | reconstituted := packetToString(outgoingPacket) |
| 2462 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2463 | } |
| 2464 | |
| 2465 | func TestGetNextResponseDecode(t *testing.T) { |
| 2466 | goodMessage := "285e3a0a00ab0202000400080334000000000000000000000000000000000000000000000000000000000028" |
| 2467 | |
| 2468 | data, err := stringToPacket(goodMessage) |
| 2469 | assert.NoError(t, err) |
| 2470 | |
| 2471 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2472 | assert.NotNil(t, packet) |
| 2473 | |
| 2474 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2475 | assert.NotNil(t, packet) |
| 2476 | |
| 2477 | omciMsg, ok := omciLayer.(*OMCI) |
| 2478 | assert.True(t, ok) |
| 2479 | assert.Equal(t, omciMsg.TransactionID, uint16(0x285e)) |
| 2480 | assert.Equal(t, omciMsg.MessageType, GetNextResponseType) |
| 2481 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2482 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2483 | |
| 2484 | msgLayer := packet.Layer(LayerTypeGetNextResponse) |
| 2485 | assert.NotNil(t, msgLayer) |
| 2486 | |
| 2487 | vlanOpTable := []byte{0x08, 0x03, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2488 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 2489 | |
| 2490 | response, ok2 := msgLayer.(*GetNextResponse) |
| 2491 | assert.True(t, ok2) |
| 2492 | assert.NotNil(t, response) |
| 2493 | assert.Equal(t, me.ExtendedVlanTaggingOperationConfigurationDataClassID, response.EntityClass) |
| 2494 | assert.Equal(t, uint16(0x0202), response.EntityInstance) |
| 2495 | assert.Equal(t, me.Success, response.Result) |
| 2496 | assert.Equal(t, uint16(0x0400), response.AttributeMask) |
| 2497 | |
| 2498 | // For GetNextResponse frames, caller is responsible for trimming last packet to remaining |
| 2499 | // size |
| 2500 | expectedOctets := 16 |
| 2501 | value := response.Attributes["ReceivedFrameVlanTaggingOperationTable"] |
| 2502 | assert.Equal(t, vlanOpTable, value.([]byte)[:expectedOctets]) |
| 2503 | |
| 2504 | // Verify string output for message |
| 2505 | packetString := packet.String() |
| 2506 | assert.NotZero(t, len(packetString)) |
| 2507 | } |
| 2508 | |
| 2509 | func TestGetNextResponseSerialize(t *testing.T) { |
| 2510 | goodMessage := "285e3a0a00ab0202000400080334000000000000000000000000000000000000000000000000000000000028" |
| 2511 | |
| 2512 | omciLayer := &OMCI{ |
| 2513 | TransactionID: 0x285e, |
| 2514 | MessageType: GetNextResponseType, |
| 2515 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2516 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2517 | } |
| 2518 | vlanOpTable := []byte{0x08, 0x03, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2519 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 2520 | |
| 2521 | request := &GetNextResponse{ |
| 2522 | MeBasePacket: MeBasePacket{ |
| 2523 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 2524 | EntityInstance: uint16(0x0202), |
| 2525 | }, |
| 2526 | Result: me.Success, |
| 2527 | AttributeMask: uint16(0x0400), |
| 2528 | Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": vlanOpTable}, |
| 2529 | } |
| 2530 | // Test serialization back to former string |
| 2531 | var options gopacket.SerializeOptions |
| 2532 | options.FixLengths = true |
| 2533 | |
| 2534 | buffer := gopacket.NewSerializeBuffer() |
| 2535 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2536 | assert.NoError(t, err) |
| 2537 | |
| 2538 | outgoingPacket := buffer.Bytes() |
| 2539 | reconstituted := packetToString(outgoingPacket) |
| 2540 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2541 | } |
| 2542 | |
| 2543 | // TODO: Create request/response tests for all of the following types//GetCurrentData, |
| 2544 | //SetTable} |
| 2545 | |
| 2546 | func TestAlarmNotificationDecode(t *testing.T) { |
| 2547 | goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2548 | data, err := stringToPacket(goodMessage) |
| 2549 | assert.NoError(t, err) |
| 2550 | |
| 2551 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2552 | assert.NotNil(t, packet) |
| 2553 | |
| 2554 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2555 | assert.NotNil(t, packet) |
| 2556 | |
| 2557 | omciMsg, ok := omciLayer.(*OMCI) |
| 2558 | assert.True(t, ok) |
| 2559 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2560 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2561 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2562 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2563 | |
| 2564 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2565 | assert.NotNil(t, msgLayer) |
| 2566 | |
| 2567 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2568 | assert.True(t, ok2) |
| 2569 | assert.NotNil(t, request) |
| 2570 | assert.Equal(t, request.EntityClass, me.PhysicalPathTerminationPointEthernetUniClassID) |
| 2571 | assert.Equal(t, request.EntityInstance, uint16(0x104)) |
| 2572 | assert.Equal(t, request.AlarmBitmap, [28]byte{ |
| 2573 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2574 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2575 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2576 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2577 | }) |
| 2578 | assert.Equal(t, request.AlarmSequenceNumber, byte(5)) |
| 2579 | |
| 2580 | // Verify string output for message |
| 2581 | packetString := packet.String() |
| 2582 | assert.NotZero(t, len(packetString)) |
| 2583 | } |
| 2584 | |
| 2585 | func TestAlarmNotificationSerialize(t *testing.T) { |
| 2586 | goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2587 | |
| 2588 | omciLayer := &OMCI{ |
| 2589 | TransactionID: 0, |
| 2590 | MessageType: AlarmNotificationType, |
| 2591 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2592 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2593 | } |
| 2594 | request := &AlarmNotificationMsg{ |
| 2595 | MeBasePacket: MeBasePacket{ |
| 2596 | EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 2597 | EntityInstance: uint16(0x104), |
| 2598 | }, |
| 2599 | AlarmBitmap: [28]byte{ |
| 2600 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2601 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2602 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2603 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2604 | }, |
| 2605 | AlarmSequenceNumber: byte(5), |
| 2606 | } |
| 2607 | // Test serialization back to former string |
| 2608 | var options gopacket.SerializeOptions |
| 2609 | options.FixLengths = true |
| 2610 | |
| 2611 | buffer := gopacket.NewSerializeBuffer() |
| 2612 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2613 | assert.NoError(t, err) |
| 2614 | |
| 2615 | outgoingPacket := buffer.Bytes() |
| 2616 | reconstituted := packetToString(outgoingPacket) |
| 2617 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2618 | } |
| 2619 | |
| 2620 | func TestAttributeValueChangeDecode(t *testing.T) { |
| 2621 | goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028" |
| 2622 | data, err := stringToPacket(goodMessage) |
| 2623 | assert.NoError(t, err) |
| 2624 | |
| 2625 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2626 | assert.NotNil(t, packet) |
| 2627 | |
| 2628 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 2629 | assert.NotNil(t, packet) |
| 2630 | |
| 2631 | omciMsg, ok := omciLayer.(*OMCI) |
| 2632 | assert.True(t, ok) |
| 2633 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2634 | assert.Equal(t, omciMsg.MessageType, AttributeValueChangeType) |
| 2635 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2636 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2637 | |
| 2638 | msgLayer := packet.Layer(LayerTypeAttributeValueChange) |
| 2639 | assert.NotNil(t, msgLayer) |
| 2640 | |
| 2641 | request, ok2 := msgLayer.(*AttributeValueChangeMsg) |
| 2642 | assert.True(t, ok2) |
| 2643 | assert.NotNil(t, request) |
| 2644 | assert.Equal(t, request.AttributeMask, uint16(0x8000)) |
| 2645 | assert.Equal(t, request.EntityClass, me.SoftwareImageClassID) |
| 2646 | assert.Equal(t, request.EntityInstance, uint16(0)) |
| 2647 | assert.Equal(t, request.Attributes["Version"], []byte{ |
| 2648 | 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36, |
| 2649 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) |
| 2650 | |
| 2651 | // Verify string output for message |
| 2652 | packetString := packet.String() |
| 2653 | assert.NotZero(t, len(packetString)) |
| 2654 | } |
| 2655 | |
| 2656 | func TestAttributeValueChangeSerialize(t *testing.T) { |
| 2657 | goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028" |
| 2658 | |
| 2659 | omciLayer := &OMCI{ |
| 2660 | TransactionID: 0, |
| 2661 | MessageType: AttributeValueChangeType, |
| 2662 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2663 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2664 | } |
| 2665 | request := &AttributeValueChangeMsg{ |
| 2666 | MeBasePacket: MeBasePacket{ |
| 2667 | EntityClass: me.SoftwareImageClassID, |
| 2668 | EntityInstance: uint16(0), |
| 2669 | }, |
| 2670 | AttributeMask: uint16(0x8000), |
| 2671 | Attributes: me.AttributeValueMap{ |
| 2672 | "Version": []byte{ |
| 2673 | 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36, |
| 2674 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2675 | }, |
| 2676 | }, |
| 2677 | } |
| 2678 | // Test serialization back to former string |
| 2679 | var options gopacket.SerializeOptions |
| 2680 | options.FixLengths = true |
| 2681 | |
| 2682 | buffer := gopacket.NewSerializeBuffer() |
| 2683 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2684 | assert.NoError(t, err) |
| 2685 | |
| 2686 | outgoingPacket := buffer.Bytes() |
| 2687 | reconstituted := packetToString(outgoingPacket) |
| 2688 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2689 | } |
| 2690 | |
| 2691 | // TODO: Create notification tests for all of the following types |
| 2692 | //TestResult, |