Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 3 | * Copyright 2020-present Open Networking Foundation |
| 4 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 8 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 10 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 16 | */ |
| 17 | package omci_test |
| 18 | |
| 19 | import ( |
| 20 | "encoding/base64" |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 21 | "encoding/binary" |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 22 | "fmt" |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 23 | "github.com/google/gopacket" |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 24 | . "github.com/opencord/omci-lib-go" |
| 25 | me "github.com/opencord/omci-lib-go/generated" |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 26 | "github.com/stretchr/testify/assert" |
| 27 | "strings" |
| 28 | "testing" |
| 29 | ) |
| 30 | |
| 31 | var allMsgTypes = [...]me.MsgType{ |
| 32 | me.Create, |
| 33 | me.Delete, |
| 34 | me.Set, |
| 35 | me.Get, |
| 36 | me.GetAllAlarms, |
| 37 | me.GetAllAlarmsNext, |
| 38 | me.MibUpload, |
| 39 | me.MibUploadNext, |
| 40 | me.MibReset, |
| 41 | me.AlarmNotification, |
| 42 | me.AttributeValueChange, |
| 43 | me.Test, |
| 44 | me.StartSoftwareDownload, |
| 45 | me.DownloadSection, |
| 46 | me.EndSoftwareDownload, |
| 47 | me.ActivateSoftware, |
| 48 | me.CommitSoftware, |
| 49 | me.SynchronizeTime, |
| 50 | me.Reboot, |
| 51 | me.GetNext, |
| 52 | me.TestResult, |
| 53 | me.GetCurrentData, |
| 54 | me.SetTable} |
| 55 | |
| 56 | var allMessageTypes = [...]MessageType{ |
| 57 | CreateRequestType, |
| 58 | CreateResponseType, |
| 59 | DeleteRequestType, |
| 60 | DeleteResponseType, |
| 61 | SetRequestType, |
| 62 | SetResponseType, |
| 63 | GetRequestType, |
| 64 | GetResponseType, |
| 65 | GetAllAlarmsRequestType, |
| 66 | GetAllAlarmsResponseType, |
| 67 | GetAllAlarmsNextRequestType, |
| 68 | GetAllAlarmsNextResponseType, |
| 69 | MibUploadRequestType, |
| 70 | MibUploadResponseType, |
| 71 | MibUploadNextRequestType, |
| 72 | MibUploadNextResponseType, |
| 73 | MibResetRequestType, |
| 74 | MibResetResponseType, |
| 75 | TestRequestType, |
| 76 | TestResponseType, |
| 77 | StartSoftwareDownloadRequestType, |
| 78 | StartSoftwareDownloadResponseType, |
| 79 | DownloadSectionRequestType, |
| 80 | DownloadSectionResponseType, |
| 81 | EndSoftwareDownloadRequestType, |
| 82 | EndSoftwareDownloadResponseType, |
| 83 | ActivateSoftwareRequestType, |
| 84 | ActivateSoftwareResponseType, |
| 85 | CommitSoftwareRequestType, |
| 86 | CommitSoftwareResponseType, |
| 87 | SynchronizeTimeRequestType, |
| 88 | SynchronizeTimeResponseType, |
| 89 | RebootRequestType, |
| 90 | RebootResponseType, |
| 91 | GetNextRequestType, |
| 92 | GetNextResponseType, |
| 93 | GetCurrentDataRequestType, |
| 94 | GetCurrentDataResponseType, |
| 95 | SetTableRequestType, |
| 96 | SetTableResponseType, |
| 97 | // Autonomous ONU messages |
| 98 | AlarmNotificationType, |
| 99 | AttributeValueChangeType, |
| 100 | TestResultType, |
| 101 | } |
| 102 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 103 | var allExtendedMessageTypes = [...]MessageType{ |
| 104 | GetRequestType, |
| 105 | GetResponseType, |
| 106 | } |
| 107 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 108 | var allResults = [...]me.Results{ |
| 109 | me.Success, |
| 110 | me.ProcessingError, |
| 111 | me.NotSupported, |
| 112 | me.ParameterError, |
| 113 | me.UnknownEntity, |
| 114 | me.UnknownInstance, |
| 115 | me.DeviceBusy, |
| 116 | me.InstanceExists} |
| 117 | |
| 118 | // TestMsgTypeStrings tests that base message types can be printed |
| 119 | func TestMsgTypeStrings(t *testing.T) { |
| 120 | for _, msg := range allMsgTypes { |
| 121 | strMsg := msg.String() |
| 122 | assert.NotEqual(t, len(strMsg), 0) |
| 123 | } |
| 124 | unknown := me.MsgType(0xFF) |
| 125 | strMsg := unknown.String() |
| 126 | assert.NotEqual(t, len(strMsg), 0) |
| 127 | } |
| 128 | |
| 129 | // TestMessageTypeStrings tests that request/response/notification |
| 130 | // message types can be printed |
| 131 | func TestMessageTypeStrings(t *testing.T) { |
| 132 | for _, msg := range allMessageTypes { |
| 133 | strMsg := msg.String() |
| 134 | assert.NotEqual(t, len(strMsg), 0) |
| 135 | } |
| 136 | unknown := MessageType(0xFF) |
| 137 | strMsg := unknown.String() |
| 138 | assert.NotEqual(t, len(strMsg), 0) |
| 139 | } |
| 140 | |
| 141 | func TestResultsStrings(t *testing.T) { |
| 142 | for _, code := range allResults { |
| 143 | strMsg := code.String() |
| 144 | assert.NotEqual(t, len(strMsg), 0) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // TestOmciDecode will test for proper error checking of things that |
| 149 | // are invalid at the OMCI decode layer |
| 150 | func TestOmciDecode(t *testing.T) { |
| 151 | // TID = 0 on autonomous ONU notifications only. Get packet back but ErrorLayer() |
| 152 | // returns non-nil |
| 153 | tidZeroOnNonNotification := "0000440A010C01000400800003010000" + |
| 154 | "00000000000000000000000000000000" + |
| 155 | "000000000000000000000028" |
| 156 | |
| 157 | data, err := stringToPacket(tidZeroOnNonNotification) |
| 158 | assert.NoError(t, err) |
| 159 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 160 | assert.NotNil(t, packet) |
| 161 | assert.NotNil(t, packet.ErrorLayer()) |
| 162 | |
| 163 | // Only Baseline and Extended Message types allowed |
| 164 | invalidMessageType := "000C440F010C01000400800003010000" + |
| 165 | "00000000000000000000000000000000" + |
| 166 | "000000000000000000000028" |
| 167 | |
| 168 | data, err = stringToPacket(invalidMessageType) |
| 169 | assert.NoError(t, err) |
| 170 | packet = gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 171 | assert.NotNil(t, packet) |
| 172 | assert.NotNil(t, packet.ErrorLayer()) |
| 173 | |
| 174 | // Bad baseline message length |
| 175 | badBaselineMsgLength := "000C440A010C01000400800003010000" + |
| 176 | "00000000000000000000000000000000" + |
| 177 | "000000000000000000000029" |
| 178 | |
| 179 | data, err = stringToPacket(badBaselineMsgLength) |
| 180 | assert.NoError(t, err) |
| 181 | packet = gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 182 | assert.NotNil(t, packet) |
| 183 | assert.NotNil(t, packet.ErrorLayer()) |
| 184 | |
| 185 | // Bad extended message length |
| 186 | badExtendedMsgLength := "000C440B010C010000290400800003010000" + |
| 187 | "00000000000000000000000000000000" + |
| 188 | "00000000000000000000" |
| 189 | |
| 190 | data, err = stringToPacket(badExtendedMsgLength) |
| 191 | assert.NoError(t, err) |
| 192 | packet = gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 193 | assert.NotNil(t, packet) |
| 194 | assert.NotNil(t, packet.ErrorLayer()) |
| 195 | |
| 196 | // Huge extended message length |
| 197 | hugeExtendedMsgLength := "000C440B010C010007BD0400800003010000" + |
| 198 | "00000000000000000000000000000000" + |
| 199 | "00000000000000000000" |
| 200 | |
| 201 | data, err = stringToPacket(hugeExtendedMsgLength) |
| 202 | assert.NoError(t, err) |
| 203 | packet = gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 204 | assert.NotNil(t, packet) |
| 205 | assert.NotNil(t, packet.ErrorLayer()) |
| 206 | } |
| 207 | |
| 208 | // TestOmciSerialization will test for proper error checking of things that |
| 209 | // are invalid at the OMCI layer |
| 210 | func TestOmciSerialization(t *testing.T) { |
| 211 | goodMessage := "000C440A010C0100040080000301000000000000000000000000000000000000000000000000000000000028" |
| 212 | |
| 213 | omciLayerDefaults := &OMCI{ |
| 214 | TransactionID: 0x0c, |
| 215 | MessageType: CreateRequestType, |
| 216 | // DeviceIdentifier: BaselineIdent, // Optional, defaults to Baseline |
| 217 | // Length: 0x28, // Optional, defaults to 40 octets |
| 218 | } |
| 219 | omciLayerFixed := &OMCI{ |
| 220 | TransactionID: 0x0c, |
| 221 | MessageType: CreateRequestType, |
| 222 | DeviceIdentifier: BaselineIdent, |
| 223 | Length: 0x28, |
| 224 | } |
| 225 | request := &CreateRequest{ |
| 226 | MeBasePacket: MeBasePacket{ |
| 227 | EntityClass: me.GemPortNetworkCtpClassID, |
| 228 | EntityInstance: uint16(0x100), |
| 229 | }, |
| 230 | Attributes: me.AttributeValueMap{ |
| 231 | "PortId": 0x400, |
| 232 | "TContPointer": 0x8000, |
| 233 | "Direction": 3, |
| 234 | "TrafficManagementPointerForUpstream": 0x100, |
| 235 | "TrafficDescriptorProfilePointerForUpstream": 0, |
| 236 | "PriorityQueuePointerForDownStream": 0, |
| 237 | "TrafficDescriptorProfilePointerForDownstream": 0, |
| 238 | "EncryptionKeyRing": 0, |
| 239 | }, |
| 240 | } |
| 241 | // Test serialization back to former string (using defaults in the message parts) |
| 242 | var options gopacket.SerializeOptions |
| 243 | options.FixLengths = true |
| 244 | |
| 245 | buffer := gopacket.NewSerializeBuffer() |
| 246 | err := gopacket.SerializeLayers(buffer, options, omciLayerDefaults, request) |
| 247 | assert.NoError(t, err) |
| 248 | |
| 249 | outgoingPacket := buffer.Bytes() |
| 250 | reconstituted := packetToString(outgoingPacket) |
| 251 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 252 | |
| 253 | // Test serialization back to former string (using explicit values in the message parts) |
| 254 | buffer = gopacket.NewSerializeBuffer() |
| 255 | err = gopacket.SerializeLayers(buffer, options, omciLayerFixed, request) |
| 256 | assert.NoError(t, err) |
| 257 | |
| 258 | outgoingPacket = buffer.Bytes() |
| 259 | reconstituted = packetToString(outgoingPacket) |
| 260 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 261 | } |
| 262 | |
| 263 | func TestCreateRequestDecode(t *testing.T) { |
| 264 | goodMessage := "000C440A010C01000400800003010000" + |
| 265 | "00000000000000000000000000000000" + |
| 266 | "000000000000000000000028" |
| 267 | data, err := stringToPacket(goodMessage) |
| 268 | assert.NoError(t, err) |
| 269 | |
| 270 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 271 | assert.NotNil(t, packet) |
| 272 | |
| 273 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 274 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 275 | |
| 276 | omciMsg, ok := omciLayer.(*OMCI) |
| 277 | assert.True(t, ok) |
| 278 | assert.Equal(t, omciMsg.TransactionID, uint16(0xc)) |
| 279 | assert.Equal(t, omciMsg.MessageType, CreateRequestType) |
| 280 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 281 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 282 | |
| 283 | msgLayer := packet.Layer(LayerTypeCreateRequest) |
| 284 | assert.NotNil(t, msgLayer) |
| 285 | |
| 286 | request, ok2 := msgLayer.(*CreateRequest) |
| 287 | assert.True(t, ok2) |
| 288 | assert.Equal(t, request.EntityClass, me.GemPortNetworkCtpClassID) |
| 289 | assert.Equal(t, request.EntityInstance, uint16(0x100)) |
| 290 | |
| 291 | attributes := request.Attributes |
| 292 | assert.NotNil(t, attributes) |
| 293 | |
| 294 | // As this is a create request, gather up all set-by-create attributes |
| 295 | // make sure we got them all, and nothing else |
| 296 | meDefinition, omciErr := me.LoadManagedEntityDefinition(request.EntityClass) |
| 297 | assert.NotNil(t, omciErr) |
| 298 | assert.Equal(t, omciErr.StatusCode(), me.Success) |
| 299 | |
| 300 | attrDefs := meDefinition.GetAttributeDefinitions() |
| 301 | |
| 302 | sbcMask := getSbcMask(meDefinition) |
| 303 | for index := uint(1); index < uint(len(attrDefs)); index++ { |
| 304 | attrName := attrDefs[index].GetName() |
| 305 | |
| 306 | if sbcMask&uint16(1<<(uint)(16-index)) != 0 { |
| 307 | _, ok3 := attributes[attrName] |
| 308 | assert.True(t, ok3) |
| 309 | } else { |
| 310 | _, ok3 := attributes[attrName] |
| 311 | assert.False(t, ok3) |
| 312 | } |
| 313 | //fmt.Printf("Name: %v, Value: %v\n", attrName, attributes[attrName]) |
| 314 | } |
| 315 | // Test serialization back to former string |
| 316 | var options gopacket.SerializeOptions |
| 317 | options.FixLengths = true |
| 318 | |
| 319 | buffer := gopacket.NewSerializeBuffer() |
| 320 | err = gopacket.SerializeLayers(buffer, options, omciMsg, request) |
| 321 | assert.NoError(t, err) |
| 322 | |
| 323 | outgoingPacket := buffer.Bytes() |
| 324 | reconstituted := packetToString(outgoingPacket) |
| 325 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 326 | |
| 327 | // Verify string output for message |
| 328 | packetString := packet.String() |
| 329 | assert.NotZero(t, len(packetString)) |
| 330 | } |
| 331 | |
| 332 | func TestCreateRequestSerialize(t *testing.T) { |
| 333 | goodMessage := "000C440A010C0100040080000301000000000000000000000000000000000000000000000000000000000028" |
| 334 | |
| 335 | omciLayer := &OMCI{ |
| 336 | TransactionID: 0x0c, |
| 337 | MessageType: CreateRequestType, |
| 338 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 339 | // Length: 0x28, // Optional, defaults to 40 octets |
| 340 | } |
| 341 | request := &CreateRequest{ |
| 342 | MeBasePacket: MeBasePacket{ |
| 343 | EntityClass: me.GemPortNetworkCtpClassID, |
| 344 | EntityInstance: uint16(0x100), |
| 345 | }, |
| 346 | Attributes: me.AttributeValueMap{ |
| 347 | "PortId": 0x400, |
| 348 | "TContPointer": 0x8000, |
| 349 | "Direction": 3, |
| 350 | "TrafficManagementPointerForUpstream": 0x100, |
| 351 | "TrafficDescriptorProfilePointerForUpstream": 0, |
| 352 | "PriorityQueuePointerForDownStream": 0, |
| 353 | "TrafficDescriptorProfilePointerForDownstream": 0, |
| 354 | "EncryptionKeyRing": 0, |
| 355 | }, |
| 356 | } |
| 357 | // Test serialization back to former string |
| 358 | var options gopacket.SerializeOptions |
| 359 | options.FixLengths = true |
| 360 | |
| 361 | buffer := gopacket.NewSerializeBuffer() |
| 362 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 363 | assert.NoError(t, err) |
| 364 | |
| 365 | outgoingPacket := buffer.Bytes() |
| 366 | reconstituted := packetToString(outgoingPacket) |
| 367 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 368 | } |
| 369 | |
| 370 | func TestCreateResponseDecode(t *testing.T) { |
| 371 | goodMessage := "0157240a01100001000000000000000000000000000000000000000000000000000000000000000000000028a9ccbeb9" |
| 372 | data, err := stringToPacket(goodMessage) |
| 373 | assert.NoError(t, err) |
| 374 | |
| 375 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 376 | assert.NotNil(t, packet) |
| 377 | |
| 378 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 379 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 380 | |
| 381 | omciMsg, ok := omciLayer.(*OMCI) |
| 382 | assert.True(t, ok) |
| 383 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0157)) |
| 384 | assert.Equal(t, omciMsg.MessageType, CreateResponseType) |
| 385 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 386 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 387 | |
| 388 | msgLayer := packet.Layer(LayerTypeCreateResponse) |
| 389 | assert.NotNil(t, msgLayer) |
| 390 | |
| 391 | response, ok2 := msgLayer.(*CreateResponse) |
| 392 | assert.True(t, ok2) |
| 393 | assert.NotNil(t, response) |
| 394 | |
| 395 | // Verify string output for message |
| 396 | packetString := packet.String() |
| 397 | assert.NotZero(t, len(packetString)) |
| 398 | } |
| 399 | |
| 400 | func TestCreateResponseSerialize(t *testing.T) { |
| 401 | goodMessage := "0157240a01100001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 402 | |
| 403 | omciLayer := &OMCI{ |
| 404 | TransactionID: 0x0157, |
| 405 | MessageType: CreateResponseType, |
| 406 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 407 | // Length: 0x28, // Optional, defaults to 40 octets |
| 408 | } |
| 409 | request := &CreateResponse{ |
| 410 | MeBasePacket: MeBasePacket{ |
| 411 | EntityClass: me.GalEthernetProfileClassID, |
| 412 | EntityInstance: uint16(1), |
| 413 | }, |
| 414 | Result: me.Success, |
| 415 | AttributeExecutionMask: uint16(0), |
| 416 | } |
| 417 | // Test serialization back to former string |
| 418 | var options gopacket.SerializeOptions |
| 419 | options.FixLengths = true |
| 420 | |
| 421 | buffer := gopacket.NewSerializeBuffer() |
| 422 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 423 | assert.NoError(t, err) |
| 424 | |
| 425 | outgoingPacket := buffer.Bytes() |
| 426 | reconstituted := packetToString(outgoingPacket) |
| 427 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 428 | } |
| 429 | |
| 430 | func TestDeleteRequestDecode(t *testing.T) { |
| 431 | goodMessage := "0211460a00ab0202000000000000000000000000000000000000000000000000000000000000000000000028" |
| 432 | data, err := stringToPacket(goodMessage) |
| 433 | assert.NoError(t, err) |
| 434 | |
| 435 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 436 | assert.NotNil(t, packet) |
| 437 | |
| 438 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 439 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 440 | |
| 441 | omciMsg, ok := omciLayer.(*OMCI) |
| 442 | assert.True(t, ok) |
| 443 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0211)) |
| 444 | assert.Equal(t, omciMsg.MessageType, DeleteRequestType) |
| 445 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 446 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 447 | |
| 448 | msgLayer := packet.Layer(LayerTypeDeleteRequest) |
| 449 | |
| 450 | assert.NotNil(t, msgLayer) |
| 451 | |
| 452 | request, ok2 := msgLayer.(*DeleteRequest) |
| 453 | assert.True(t, ok2) |
| 454 | assert.NotNil(t, request) |
| 455 | |
| 456 | // Verify string output for message |
| 457 | packetString := packet.String() |
| 458 | assert.NotZero(t, len(packetString)) |
| 459 | } |
| 460 | |
| 461 | func TestDeleteRequestSerialize(t *testing.T) { |
| 462 | goodMessage := "0211460a00ab0202000000000000000000000000000000000000000000000000000000000000000000000028" |
| 463 | |
| 464 | omciLayer := &OMCI{ |
| 465 | TransactionID: 0x0211, |
| 466 | MessageType: DeleteRequestType, |
| 467 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 468 | // Length: 0x28, // Optional, defaults to 40 octets |
| 469 | } |
| 470 | request := &DeleteRequest{ |
| 471 | MeBasePacket: MeBasePacket{ |
| 472 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 473 | EntityInstance: uint16(0x202), |
| 474 | }, |
| 475 | } |
| 476 | // Test serialization back to former string |
| 477 | var options gopacket.SerializeOptions |
| 478 | options.FixLengths = true |
| 479 | |
| 480 | buffer := gopacket.NewSerializeBuffer() |
| 481 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 482 | assert.NoError(t, err) |
| 483 | |
| 484 | outgoingPacket := buffer.Bytes() |
| 485 | reconstituted := packetToString(outgoingPacket) |
| 486 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 487 | } |
| 488 | |
| 489 | func TestDeleteResponseDecode(t *testing.T) { |
| 490 | goodMessage := "0211260a00ab0202000000000000000000000000000000000000000000000000000000000000000000000028013437fb" |
| 491 | data, err := stringToPacket(goodMessage) |
| 492 | assert.NoError(t, err) |
| 493 | |
| 494 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 495 | assert.NotNil(t, packet) |
| 496 | |
| 497 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 498 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 499 | |
| 500 | omciMsg, ok := omciLayer.(*OMCI) |
| 501 | assert.True(t, ok) |
| 502 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0211)) |
| 503 | assert.Equal(t, omciMsg.MessageType, DeleteResponseType) |
| 504 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 505 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 506 | |
| 507 | msgLayer := packet.Layer(LayerTypeDeleteResponse) |
| 508 | |
| 509 | assert.NotNil(t, msgLayer) |
| 510 | |
| 511 | response, ok2 := msgLayer.(*DeleteResponse) |
| 512 | assert.True(t, ok2) |
| 513 | assert.NotNil(t, response) |
| 514 | |
| 515 | // Verify string output for message |
| 516 | packetString := packet.String() |
| 517 | assert.NotZero(t, len(packetString)) |
| 518 | } |
| 519 | |
| 520 | func TestDeleteResponseSerialize(t *testing.T) { |
| 521 | goodMessage := "0211260a00ab0202000000000000000000000000000000000000000000000000000000000000000000000028" |
| 522 | |
| 523 | omciLayer := &OMCI{ |
| 524 | TransactionID: 0x0211, |
| 525 | MessageType: DeleteResponseType, |
| 526 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 527 | // Length: 0x28, // Optional, defaults to 40 octets |
| 528 | } |
| 529 | request := &DeleteResponse{ |
| 530 | MeBasePacket: MeBasePacket{ |
| 531 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 532 | EntityInstance: uint16(0x202), |
| 533 | }, |
| 534 | Result: me.Success, |
| 535 | } |
| 536 | // Test serialization back to former string |
| 537 | var options gopacket.SerializeOptions |
| 538 | options.FixLengths = true |
| 539 | |
| 540 | buffer := gopacket.NewSerializeBuffer() |
| 541 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 542 | assert.NoError(t, err) |
| 543 | |
| 544 | outgoingPacket := buffer.Bytes() |
| 545 | reconstituted := packetToString(outgoingPacket) |
| 546 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 547 | } |
| 548 | |
| 549 | func TestSetRequestDecode(t *testing.T) { |
| 550 | goodMessage := "0107480a01000000020000000000000000000000000000000000000000000000000000000000000000000028" |
| 551 | data, err := stringToPacket(goodMessage) |
| 552 | assert.NoError(t, err) |
| 553 | |
| 554 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 555 | assert.NotNil(t, packet) |
| 556 | |
| 557 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 558 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 559 | |
| 560 | omciMsg, ok := omciLayer.(*OMCI) |
| 561 | assert.True(t, ok) |
| 562 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0107)) |
| 563 | assert.Equal(t, omciMsg.MessageType, SetRequestType) |
| 564 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 565 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 566 | |
| 567 | msgLayer := packet.Layer(LayerTypeSetRequest) |
| 568 | assert.NotNil(t, msgLayer) |
| 569 | |
| 570 | request, ok2 := msgLayer.(*SetRequest) |
| 571 | assert.True(t, ok2) |
| 572 | assert.NotNil(t, request) |
| 573 | |
| 574 | // Verify string output for message |
| 575 | packetString := packet.String() |
| 576 | assert.NotZero(t, len(packetString)) |
| 577 | } |
| 578 | |
| 579 | func TestSetRequestSerialize(t *testing.T) { |
| 580 | goodMessage := "0107480a01000000020000000000000000000000000000000000000000000000000000000000000000000028" |
| 581 | |
| 582 | omciLayer := &OMCI{ |
| 583 | TransactionID: 0x0107, |
| 584 | MessageType: SetRequestType, |
| 585 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 586 | // Length: 0x28, // Optional, defaults to 40 octets |
| 587 | } |
| 588 | request := &SetRequest{ |
| 589 | MeBasePacket: MeBasePacket{ |
| 590 | EntityClass: me.OnuGClassID, |
| 591 | EntityInstance: uint16(0), |
| 592 | }, |
| 593 | AttributeMask: uint16(0x200), |
| 594 | Attributes: me.AttributeValueMap{"AdministrativeState": byte(0)}, |
| 595 | } |
| 596 | // Test serialization back to former string |
| 597 | var options gopacket.SerializeOptions |
| 598 | options.FixLengths = true |
| 599 | |
| 600 | buffer := gopacket.NewSerializeBuffer() |
| 601 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 602 | assert.NoError(t, err) |
| 603 | |
| 604 | outgoingPacket := buffer.Bytes() |
| 605 | reconstituted := packetToString(outgoingPacket) |
| 606 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 607 | } |
| 608 | |
| 609 | func TestSetResponseDecode(t *testing.T) { |
| 610 | goodMessage := "0107280a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 611 | data, err := stringToPacket(goodMessage) |
| 612 | assert.NoError(t, err) |
| 613 | |
| 614 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 615 | assert.NotNil(t, packet) |
| 616 | |
| 617 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 618 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 619 | |
| 620 | omciMsg, ok := omciLayer.(*OMCI) |
| 621 | assert.True(t, ok) |
| 622 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0107)) |
| 623 | assert.Equal(t, omciMsg.MessageType, SetResponseType) |
| 624 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 625 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 626 | |
| 627 | msgLayer := packet.Layer(LayerTypeSetResponse) |
| 628 | assert.NotNil(t, msgLayer) |
| 629 | |
| 630 | response, ok2 := msgLayer.(*SetResponse) |
| 631 | assert.True(t, ok2) |
| 632 | assert.NotNil(t, response) |
| 633 | |
| 634 | // Verify string output for message |
| 635 | packetString := packet.String() |
| 636 | assert.NotZero(t, len(packetString)) |
| 637 | } |
| 638 | |
| 639 | func TestSetResponseSerialize(t *testing.T) { |
| 640 | goodMessage := "0107280a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 641 | |
| 642 | omciLayer := &OMCI{ |
| 643 | TransactionID: 0x0107, |
| 644 | MessageType: SetResponseType, |
| 645 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 646 | // Length: 0x28, // Optional, defaults to 40 octets |
| 647 | } |
| 648 | request := &SetResponse{ |
| 649 | MeBasePacket: MeBasePacket{ |
| 650 | EntityClass: me.OnuGClassID, |
| 651 | EntityInstance: uint16(0), |
| 652 | }, |
| 653 | Result: me.Success, |
| 654 | } |
| 655 | // Test serialization back to former string |
| 656 | var options gopacket.SerializeOptions |
| 657 | options.FixLengths = true |
| 658 | |
| 659 | buffer := gopacket.NewSerializeBuffer() |
| 660 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 661 | assert.NoError(t, err) |
| 662 | |
| 663 | outgoingPacket := buffer.Bytes() |
| 664 | reconstituted := packetToString(outgoingPacket) |
| 665 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 666 | |
| 667 | } |
| 668 | |
| 669 | func TestSetResponseTableFailedAttributesDecode(t *testing.T) { |
| 670 | // This is a SET Response with failed and unsupported attributes |
| 671 | // TODO:Implement |
| 672 | } |
| 673 | |
| 674 | func TestSetResponseTableFailedAttributesSerialize(t *testing.T) { |
| 675 | // This is a SET Response with failed and unsupported attributes |
| 676 | // TODO:Implement |
| 677 | } |
| 678 | |
| 679 | func TestGetRequestDecode(t *testing.T) { |
| 680 | goodMessage := "035e490a01070000004400000000000000000000000000000000000000000000000000000000000000000028" |
| 681 | data, err := stringToPacket(goodMessage) |
| 682 | assert.NoError(t, err) |
| 683 | |
| 684 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 685 | assert.NotNil(t, packet) |
| 686 | |
| 687 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 688 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 689 | |
| 690 | omciMsg, ok := omciLayer.(*OMCI) |
| 691 | assert.True(t, ok) |
| 692 | assert.Equal(t, omciMsg.TransactionID, uint16(0x035e)) |
| 693 | assert.Equal(t, omciMsg.MessageType, GetRequestType) |
| 694 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 695 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 696 | |
| 697 | msgLayer := packet.Layer(LayerTypeGetRequest) |
| 698 | assert.NotNil(t, msgLayer) |
| 699 | |
| 700 | request, ok2 := msgLayer.(*GetRequest) |
| 701 | assert.True(t, ok2) |
| 702 | assert.NotNil(t, request) |
| 703 | |
| 704 | // Verify string output for message |
| 705 | packetString := packet.String() |
| 706 | assert.NotZero(t, len(packetString)) |
| 707 | } |
| 708 | |
| 709 | func TestGetRequestSerialize(t *testing.T) { |
| 710 | goodMessage := "035e490a01070000004400000000000000000000000000000000000000000000000000000000000000000028" |
| 711 | |
| 712 | omciLayer := &OMCI{ |
| 713 | TransactionID: 0x035e, |
| 714 | MessageType: GetRequestType, |
| 715 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 716 | // Length: 0x28, // Optional, defaults to 40 octets |
| 717 | } |
| 718 | request := &GetRequest{ |
| 719 | MeBasePacket: MeBasePacket{ |
| 720 | EntityClass: me.AniGClassID, |
| 721 | EntityInstance: uint16(0), |
| 722 | }, |
| 723 | AttributeMask: uint16(0x0044), |
| 724 | } |
| 725 | // Test serialization back to former string |
| 726 | var options gopacket.SerializeOptions |
| 727 | options.FixLengths = true |
| 728 | |
| 729 | buffer := gopacket.NewSerializeBuffer() |
| 730 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 731 | assert.NoError(t, err) |
| 732 | |
| 733 | outgoingPacket := buffer.Bytes() |
| 734 | reconstituted := packetToString(outgoingPacket) |
| 735 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 736 | } |
| 737 | |
| 738 | func TestGetResponseDecode(t *testing.T) { |
| 739 | goodMessage := "035e290a01070000000044dbcb05f10000000000000000000000000000000000000000000000000000000028" |
| 740 | data, err := stringToPacket(goodMessage) |
| 741 | assert.NoError(t, err) |
| 742 | |
| 743 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 744 | assert.NotNil(t, packet) |
| 745 | |
| 746 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 747 | assert.NotNil(t, omciLayer) |
| 748 | |
| 749 | omciMsg, ok := omciLayer.(*OMCI) |
| 750 | assert.True(t, ok) |
| 751 | assert.Equal(t, omciMsg.TransactionID, uint16(0x035e)) |
| 752 | assert.Equal(t, omciMsg.MessageType, GetResponseType) |
| 753 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 754 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 755 | |
| 756 | msgLayer := packet.Layer(LayerTypeGetResponse) |
| 757 | assert.NotNil(t, msgLayer) |
| 758 | |
| 759 | response, ok2 := msgLayer.(*GetResponse) |
| 760 | assert.True(t, ok2) |
| 761 | assert.NotNil(t, response) |
| 762 | assert.Equal(t, response.Result, me.Success) |
| 763 | assert.Equal(t, response.AttributeMask, uint16(0x0044)) |
| 764 | assert.Equal(t, response.Attributes["TransmitOpticalLevel"], uint16(0x05f1)) |
| 765 | assert.Equal(t, response.Attributes["OpticalSignalLevel"], uint16(0xdbcb)) |
| 766 | |
| 767 | // Verify string output for message |
| 768 | packetString := packet.String() |
| 769 | assert.NotZero(t, len(packetString)) |
| 770 | } |
| 771 | |
| 772 | func TestGetResponseSerialize(t *testing.T) { |
| 773 | goodMessage := "035e290a01070000000044dbcb05f10000000000000000000000000000000000000000000000000000000028" |
| 774 | |
| 775 | omciLayer := &OMCI{ |
| 776 | TransactionID: 0x035e, |
| 777 | MessageType: GetResponseType, |
| 778 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 779 | // Length: 0x28, // Optional, defaults to 40 octets |
| 780 | } |
| 781 | request := &GetResponse{ |
| 782 | MeBasePacket: MeBasePacket{ |
| 783 | EntityClass: me.AniGClassID, |
| 784 | EntityInstance: uint16(0), |
| 785 | }, |
| 786 | Result: 0, |
| 787 | AttributeMask: uint16(0x0044), |
| 788 | Attributes: me.AttributeValueMap{ |
| 789 | "TransmitOpticalLevel": uint16(0x05f1), |
| 790 | "OpticalSignalLevel": uint16(0xdbcb)}, |
| 791 | } |
| 792 | // Test serialization back to former string |
| 793 | var options gopacket.SerializeOptions |
| 794 | options.FixLengths = true |
| 795 | |
| 796 | buffer := gopacket.NewSerializeBuffer() |
| 797 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 798 | assert.NoError(t, err) |
| 799 | |
| 800 | outgoingPacket := buffer.Bytes() |
| 801 | reconstituted := packetToString(outgoingPacket) |
| 802 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 803 | } |
| 804 | |
| 805 | /////////////////////////////////////////////////////////////////////// |
| 806 | // Packet definitions for attributes of various types/sizes |
| 807 | func toOctets(str string) []byte { |
| 808 | data, err := base64.StdEncoding.DecodeString(str) |
| 809 | if err != nil { |
| 810 | panic(fmt.Sprintf("Invalid Base-64 string: '%v'", str)) |
| 811 | } |
| 812 | return data |
| 813 | } |
| 814 | |
| 815 | func TestGetResponseSerializeTruncationFailure(t *testing.T) { |
| 816 | // Too much data and 'fix-length' is not specified. This response has 26 |
| 817 | // octets in the requested data, but only 25 octets available |
| 818 | |
| 819 | omciLayer := &OMCI{ |
| 820 | TransactionID: 0x035e, |
| 821 | MessageType: GetResponseType, |
| 822 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 823 | // Length: 0x28, // Optional, defaults to 40 octets |
| 824 | } |
| 825 | request := &GetResponse{ |
| 826 | MeBasePacket: MeBasePacket{ |
| 827 | EntityClass: me.OnuGClassID, |
| 828 | EntityInstance: uint16(0), |
| 829 | }, |
| 830 | Result: 0, |
| 831 | AttributeMask: uint16(0xE000), |
| 832 | Attributes: me.AttributeValueMap{ |
| 833 | "VendorId": toOctets("ICAgIA=="), |
| 834 | "Version": toOctets("MAAAAAAAAAAAAAAAAAA="), |
| 835 | "SerialNumber": toOctets("AAAAAAAAAAA="), |
| 836 | }, |
| 837 | } |
| 838 | // Test serialization and verify truncation failure |
| 839 | var options gopacket.SerializeOptions |
| 840 | options.FixLengths = false |
| 841 | |
| 842 | buffer := gopacket.NewSerializeBuffer() |
| 843 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 844 | assert.Error(t, err) |
| 845 | assert.IsType(t, &me.MessageTruncatedError{}, err) |
| 846 | } |
| 847 | |
| 848 | func TestGetResponseSerializeTruncationButOkay(t *testing.T) { |
| 849 | // Too much data and 'fix-length' is specified so it packs as much as |
| 850 | // possible and adjusts the failure masks |
| 851 | |
| 852 | omciLayer := &OMCI{ |
| 853 | TransactionID: 0x035e, |
| 854 | MessageType: GetResponseType, |
| 855 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 856 | // Length: 0x28, // Optional, defaults to 40 octets |
| 857 | } |
| 858 | response := &GetResponse{ |
| 859 | MeBasePacket: MeBasePacket{ |
| 860 | EntityClass: me.OnuGClassID, |
| 861 | EntityInstance: uint16(0), |
| 862 | }, |
| 863 | Result: 0, |
| 864 | AttributeMask: uint16(0xE000), |
| 865 | Attributes: me.AttributeValueMap{ |
| 866 | "VendorId": toOctets("ICAgIA=="), |
| 867 | "Version": toOctets("MAAAAAAAAAAAAAAAAAA="), |
| 868 | "SerialNumber": toOctets("AAAAAAAAAAA="), |
| 869 | }, |
| 870 | } |
| 871 | // Test serialization and verify truncation failure |
| 872 | var options gopacket.SerializeOptions |
| 873 | options.FixLengths = true |
| 874 | |
| 875 | buffer := gopacket.NewSerializeBuffer() |
| 876 | err := gopacket.SerializeLayers(buffer, options, omciLayer, response) |
| 877 | assert.NoError(t, err) |
| 878 | |
| 879 | // Now deserialize it and see if we have the proper result (Attribute Failure) |
| 880 | // and a non-zero failed mask |
| 881 | responsePacket := buffer.Bytes() |
| 882 | packet := gopacket.NewPacket(responsePacket, LayerTypeOMCI, gopacket.NoCopy) |
| 883 | assert.NotNil(t, packet) |
| 884 | |
| 885 | omciLayer2 := packet.Layer(LayerTypeOMCI) |
| 886 | assert.NotNil(t, omciLayer2) |
| 887 | |
| 888 | omciMsg2, ok := omciLayer2.(*OMCI) |
| 889 | assert.True(t, ok) |
| 890 | assert.Equal(t, omciLayer.TransactionID, omciMsg2.TransactionID) |
| 891 | assert.Equal(t, omciLayer.MessageType, GetResponseType) |
| 892 | assert.Equal(t, omciLayer.DeviceIdentifier, BaselineIdent) |
| 893 | assert.Equal(t, omciLayer.Length, uint16(40)) |
| 894 | |
| 895 | msgLayer2 := packet.Layer(LayerTypeGetResponse) |
| 896 | assert.NotNil(t, msgLayer2) |
| 897 | |
| 898 | response2, ok2 := msgLayer2.(*GetResponse) |
| 899 | assert.True(t, ok2) |
| 900 | assert.Equal(t, me.AttributeFailure, response2.Result) |
| 901 | assert.NotZero(t, response2.AttributeMask) |
| 902 | assert.NotZero(t, response2.FailedAttributeMask) |
| 903 | assert.Zero(t, response2.UnsupportedAttributeMask) |
| 904 | } |
| 905 | |
| 906 | func TestGetResponseTableFailedAttributesDecode(t *testing.T) { |
| 907 | // This is a GET Response with failed and unsupported attributes |
| 908 | // TODO:Implement |
| 909 | } |
| 910 | |
| 911 | func TestGetResponseTableFailedAttributesSerialize(t *testing.T) { |
| 912 | // This is a GET Response with failed and unsupported attributes |
| 913 | // TODO:Implement |
| 914 | } |
| 915 | |
| 916 | func TestGetResponseTableAttributeDecode(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 TestGetResponseTableAttributeSerialize(t *testing.T) { |
| 923 | // This is a GET Response for a table attribute. It should return the attribute |
| 924 | // size as a uint16. |
| 925 | // TODO:Implement |
| 926 | } |
| 927 | |
| 928 | func TestGetAllAlarmsRequestDecode(t *testing.T) { |
| 929 | goodMessage := "04454b0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 930 | data, err := stringToPacket(goodMessage) |
| 931 | assert.NoError(t, err) |
| 932 | |
| 933 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 934 | assert.NotNil(t, packet) |
| 935 | |
| 936 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 937 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 938 | |
| 939 | omciMsg, ok := omciLayer.(*OMCI) |
| 940 | assert.True(t, ok) |
| 941 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0445)) |
| 942 | assert.Equal(t, omciMsg.MessageType, GetAllAlarmsRequestType) |
| 943 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 944 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 945 | |
| 946 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsRequest) |
| 947 | assert.NotNil(t, msgLayer) |
| 948 | |
| 949 | request, ok2 := msgLayer.(*GetAllAlarmsRequest) |
| 950 | assert.True(t, ok2) |
| 951 | assert.NotNil(t, request) |
| 952 | assert.Equal(t, request.AlarmRetrievalMode, byte(0)) |
| 953 | |
| 954 | // Verify string output for message |
| 955 | packetString := packet.String() |
| 956 | assert.NotZero(t, len(packetString)) |
| 957 | } |
| 958 | |
| 959 | func TestGetAllAlarmsRequestSerialize(t *testing.T) { |
| 960 | goodMessage := "04454b0a00020000010000000000000000000000000000000000000000000000000000000000000000000028" |
| 961 | |
| 962 | omciLayer := &OMCI{ |
| 963 | TransactionID: 0x0445, |
| 964 | MessageType: GetAllAlarmsRequestType, |
| 965 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 966 | // Length: 0x28, // Optional, defaults to 40 octets |
| 967 | } |
| 968 | request := &GetAllAlarmsRequest{ |
| 969 | MeBasePacket: MeBasePacket{ |
| 970 | EntityClass: me.OnuDataClassID, |
| 971 | EntityInstance: uint16(0), |
| 972 | }, |
| 973 | AlarmRetrievalMode: byte(1), |
| 974 | } |
| 975 | // Test serialization back to former string |
| 976 | var options gopacket.SerializeOptions |
| 977 | options.FixLengths = true |
| 978 | |
| 979 | buffer := gopacket.NewSerializeBuffer() |
| 980 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 981 | assert.NoError(t, err) |
| 982 | |
| 983 | outgoingPacket := buffer.Bytes() |
| 984 | reconstituted := packetToString(outgoingPacket) |
| 985 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 986 | } |
| 987 | |
| 988 | func TestGetAllAlarmsResponseDecode(t *testing.T) { |
| 989 | goodMessage := "04452b0a00020000000300000000000000000000000000000000000000000000000000000000000000000028" |
| 990 | data, err := stringToPacket(goodMessage) |
| 991 | assert.NoError(t, err) |
| 992 | |
| 993 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 994 | assert.NotNil(t, packet) |
| 995 | |
| 996 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 997 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 998 | |
| 999 | omciMsg, ok := omciLayer.(*OMCI) |
| 1000 | assert.True(t, ok) |
| 1001 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0445)) |
| 1002 | assert.Equal(t, omciMsg.MessageType, GetAllAlarmsResponseType) |
| 1003 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1004 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1005 | |
| 1006 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsResponse) |
| 1007 | assert.NotNil(t, msgLayer) |
| 1008 | |
| 1009 | response, ok2 := msgLayer.(*GetAllAlarmsResponse) |
| 1010 | assert.True(t, ok2) |
| 1011 | assert.NotNil(t, response) |
| 1012 | assert.Equal(t, response.NumberOfCommands, uint16(3)) |
| 1013 | |
| 1014 | // Verify string output for message |
| 1015 | packetString := packet.String() |
| 1016 | assert.NotZero(t, len(packetString)) |
| 1017 | } |
| 1018 | |
| 1019 | func TestGetAllAlarmsResponseSerialize(t *testing.T) { |
| 1020 | goodMessage := "04452b0a00020000000300000000000000000000000000000000000000000000000000000000000000000028" |
| 1021 | |
| 1022 | omciLayer := &OMCI{ |
| 1023 | TransactionID: 0x0445, |
| 1024 | MessageType: GetAllAlarmsResponseType, |
| 1025 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1026 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1027 | } |
| 1028 | request := &GetAllAlarmsResponse{ |
| 1029 | MeBasePacket: MeBasePacket{ |
| 1030 | EntityClass: me.OnuDataClassID, |
| 1031 | EntityInstance: uint16(0), |
| 1032 | }, |
| 1033 | NumberOfCommands: uint16(3), |
| 1034 | } |
| 1035 | // Test serialization back to former string |
| 1036 | var options gopacket.SerializeOptions |
| 1037 | options.FixLengths = true |
| 1038 | |
| 1039 | buffer := gopacket.NewSerializeBuffer() |
| 1040 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1041 | assert.NoError(t, err) |
| 1042 | |
| 1043 | outgoingPacket := buffer.Bytes() |
| 1044 | reconstituted := packetToString(outgoingPacket) |
| 1045 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1046 | } |
| 1047 | |
| 1048 | func TestGetAllAlarmsNextRequestDecode(t *testing.T) { |
| 1049 | goodMessage := "02344c0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1050 | |
| 1051 | data, err := stringToPacket(goodMessage) |
| 1052 | assert.NoError(t, err) |
| 1053 | |
| 1054 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1055 | assert.NotNil(t, packet) |
| 1056 | |
| 1057 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1058 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1059 | |
| 1060 | omciMsg, ok := omciLayer.(*OMCI) |
| 1061 | assert.True(t, ok) |
| 1062 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0234)) |
| 1063 | assert.Equal(t, omciMsg.MessageType, GetAllAlarmsNextRequestType) |
| 1064 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1065 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1066 | |
| 1067 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextRequest) |
| 1068 | assert.NotNil(t, msgLayer) |
| 1069 | |
| 1070 | request, ok2 := msgLayer.(*GetAllAlarmsNextRequest) |
| 1071 | assert.True(t, ok2) |
| 1072 | assert.NotNil(t, request) |
| 1073 | |
| 1074 | // Verify string output for message |
| 1075 | packetString := packet.String() |
| 1076 | assert.NotZero(t, len(packetString)) |
| 1077 | } |
| 1078 | |
| 1079 | func TestGetAllAlarmsNextRequestSerialize(t *testing.T) { |
| 1080 | goodMessage := "02344c0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1081 | |
| 1082 | omciLayer := &OMCI{ |
| 1083 | TransactionID: 0x0234, |
| 1084 | MessageType: GetAllAlarmsNextRequestType, |
| 1085 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1086 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1087 | } |
| 1088 | request := &GetAllAlarmsNextRequest{ |
| 1089 | MeBasePacket: MeBasePacket{ |
| 1090 | EntityClass: me.OnuDataClassID, |
| 1091 | EntityInstance: uint16(0), |
| 1092 | }, |
| 1093 | CommandSequenceNumber: uint16(0), |
| 1094 | } |
| 1095 | // Test serialization back to former string |
| 1096 | var options gopacket.SerializeOptions |
| 1097 | options.FixLengths = true |
| 1098 | |
| 1099 | buffer := gopacket.NewSerializeBuffer() |
| 1100 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1101 | assert.NoError(t, err) |
| 1102 | |
| 1103 | outgoingPacket := buffer.Bytes() |
| 1104 | reconstituted := packetToString(outgoingPacket) |
| 1105 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1106 | } |
| 1107 | |
| 1108 | func TestGetAllAlarmsNextResponseDecode(t *testing.T) { |
| 1109 | goodMessage := "02342c0a00020000000b01028000000000000000000000000000000000000000000000000000000000000028f040fc87" |
| 1110 | data, err := stringToPacket(goodMessage) |
| 1111 | assert.NoError(t, err) |
| 1112 | |
| 1113 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1114 | assert.NotNil(t, packet) |
| 1115 | |
| 1116 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1117 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1118 | |
| 1119 | omciMsg, ok := omciLayer.(*OMCI) |
| 1120 | assert.True(t, ok) |
| 1121 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0234)) |
| 1122 | assert.Equal(t, omciMsg.MessageType, GetAllAlarmsNextResponseType) |
| 1123 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1124 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1125 | |
| 1126 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextResponse) |
| 1127 | assert.NotNil(t, msgLayer) |
| 1128 | |
| 1129 | response, ok2 := msgLayer.(*GetAllAlarmsNextResponse) |
| 1130 | assert.True(t, ok2) |
| 1131 | assert.NotNil(t, response) |
| 1132 | |
| 1133 | var alarms [224 / 8]byte |
| 1134 | alarms[0] = 0x80 |
| 1135 | assert.Equal(t, response.AlarmEntityClass, me.PhysicalPathTerminationPointEthernetUniClassID) |
| 1136 | assert.Equal(t, response.AlarmEntityInstance, uint16(0x102)) |
| 1137 | assert.Equal(t, response.AlarmBitMap, alarms) |
| 1138 | |
| 1139 | // Verify string output for message |
| 1140 | packetString := packet.String() |
| 1141 | assert.NotZero(t, len(packetString)) |
| 1142 | } |
| 1143 | |
| 1144 | func TestGetAllAlarmsNextResponseSerialize(t *testing.T) { |
| 1145 | goodMessage := "02342c0a00020000000b01028000000000000000000000000000000000000000000000000000000000000028" |
| 1146 | |
| 1147 | omciLayer := &OMCI{ |
| 1148 | TransactionID: 0x0234, |
| 1149 | MessageType: GetAllAlarmsNextResponseType, |
| 1150 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1151 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1152 | } |
| 1153 | var alarms [224 / 8]byte |
| 1154 | alarms[0] = 0x80 |
| 1155 | |
| 1156 | request := &GetAllAlarmsNextResponse{ |
| 1157 | MeBasePacket: MeBasePacket{ |
| 1158 | EntityClass: me.OnuDataClassID, |
| 1159 | EntityInstance: uint16(0), |
| 1160 | }, |
| 1161 | AlarmEntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 1162 | AlarmEntityInstance: uint16(0x102), |
| 1163 | AlarmBitMap: alarms, |
| 1164 | } |
| 1165 | // Test serialization back to former string |
| 1166 | var options gopacket.SerializeOptions |
| 1167 | options.FixLengths = true |
| 1168 | |
| 1169 | buffer := gopacket.NewSerializeBuffer() |
| 1170 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1171 | assert.NoError(t, err) |
| 1172 | |
| 1173 | outgoingPacket := buffer.Bytes() |
| 1174 | reconstituted := packetToString(outgoingPacket) |
| 1175 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1176 | } |
| 1177 | |
| 1178 | func TestGetAllAlarmsNextResponseBadCommandNumberDecode(t *testing.T) { |
| 1179 | // Test of a GetNext Response that results when an invalid command number |
| 1180 | // is requested. In the case where the ONU receives a get all alarms next |
| 1181 | // request message in which the command sequence number is out of range, |
| 1182 | // the ONU should respond with a message in which bytes 9 to 40 are all |
| 1183 | // set to 0. This corresponds to a response with entity class 0, entity |
| 1184 | // instance 0, and bit map all 0s. |
| 1185 | //TODO: Implement |
| 1186 | } |
| 1187 | |
| 1188 | func TestGetAllAlarmsNextResponseBadCommandNumberSerialize(t *testing.T) { |
| 1189 | // Test of a GetNext Response that results when an invalid command number |
| 1190 | // is requested. |
| 1191 | //TODO: Implement |
| 1192 | } |
| 1193 | |
| 1194 | func TestMibUploadRequestDecode(t *testing.T) { |
| 1195 | goodMessage := "03604d0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1196 | data, err := stringToPacket(goodMessage) |
| 1197 | assert.NoError(t, err) |
| 1198 | |
| 1199 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1200 | assert.NotNil(t, packet) |
| 1201 | |
| 1202 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1203 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1204 | |
| 1205 | omciMsg, ok := omciLayer.(*OMCI) |
| 1206 | assert.True(t, ok) |
| 1207 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0360)) |
| 1208 | assert.Equal(t, omciMsg.MessageType, MibUploadRequestType) |
| 1209 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1210 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1211 | msgLayer := packet.Layer(LayerTypeMibUploadRequest) |
| 1212 | |
| 1213 | assert.NotNil(t, msgLayer) |
| 1214 | |
| 1215 | request, ok2 := msgLayer.(*MibUploadRequest) |
| 1216 | assert.True(t, ok2) |
| 1217 | assert.NotNil(t, request) |
| 1218 | |
| 1219 | // Verify string output for message |
| 1220 | packetString := packet.String() |
| 1221 | assert.NotZero(t, len(packetString)) |
| 1222 | } |
| 1223 | |
| 1224 | func TestMibUploadRequestSerialize(t *testing.T) { |
| 1225 | goodMessage := "03604d0a00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1226 | |
| 1227 | omciLayer := &OMCI{ |
| 1228 | TransactionID: 0x0360, |
| 1229 | MessageType: MibUploadRequestType, |
| 1230 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1231 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1232 | } |
| 1233 | var alarms [224 / 8]byte |
| 1234 | alarms[0] = 0x80 |
| 1235 | |
| 1236 | request := &MibUploadRequest{ |
| 1237 | MeBasePacket: MeBasePacket{ |
| 1238 | EntityClass: me.OnuDataClassID, |
| 1239 | EntityInstance: uint16(0), |
| 1240 | }, |
| 1241 | } |
| 1242 | // Test serialization back to former string |
| 1243 | var options gopacket.SerializeOptions |
| 1244 | options.FixLengths = true |
| 1245 | |
| 1246 | buffer := gopacket.NewSerializeBuffer() |
| 1247 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1248 | assert.NoError(t, err) |
| 1249 | |
| 1250 | outgoingPacket := buffer.Bytes() |
| 1251 | reconstituted := packetToString(outgoingPacket) |
| 1252 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1253 | } |
| 1254 | |
| 1255 | func TestMibUploadResponse(t *testing.T) { |
| 1256 | goodMessage := "03602d0a00020000011200000000000000000000000000000000000000000000000000000000000000000028" |
| 1257 | data, err := stringToPacket(goodMessage) |
| 1258 | assert.NoError(t, err) |
| 1259 | |
| 1260 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1261 | assert.NotNil(t, packet) |
| 1262 | |
| 1263 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1264 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1265 | |
| 1266 | omciMsg, ok := omciLayer.(*OMCI) |
| 1267 | assert.True(t, ok) |
| 1268 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0360)) |
| 1269 | assert.Equal(t, omciMsg.MessageType, MibUploadResponseType) |
| 1270 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1271 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1272 | |
| 1273 | msgLayer := packet.Layer(LayerTypeMibUploadResponse) |
| 1274 | assert.NotNil(t, msgLayer) |
| 1275 | |
| 1276 | response, ok2 := msgLayer.(*MibUploadResponse) |
| 1277 | assert.True(t, ok2) |
| 1278 | assert.NotNil(t, response) |
| 1279 | assert.Equal(t, response.NumberOfCommands, uint16(0x112)) |
| 1280 | } |
| 1281 | |
| 1282 | func TestMibUploadResponseSerialize(t *testing.T) { |
| 1283 | goodMessage := "03602d0a00020000011200000000000000000000000000000000000000000000000000000000000000000028" |
| 1284 | |
| 1285 | omciLayer := &OMCI{ |
| 1286 | TransactionID: 0x0360, |
| 1287 | MessageType: MibUploadResponseType, |
| 1288 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1289 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1290 | } |
| 1291 | var alarms [224 / 8]byte |
| 1292 | alarms[0] = 0x80 |
| 1293 | |
| 1294 | request := &MibUploadResponse{ |
| 1295 | MeBasePacket: MeBasePacket{ |
| 1296 | EntityClass: me.OnuDataClassID, |
| 1297 | EntityInstance: uint16(0), |
| 1298 | }, |
| 1299 | NumberOfCommands: uint16(0x112), |
| 1300 | } |
| 1301 | // Test serialization back to former string |
| 1302 | var options gopacket.SerializeOptions |
| 1303 | options.FixLengths = true |
| 1304 | |
| 1305 | buffer := gopacket.NewSerializeBuffer() |
| 1306 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1307 | assert.NoError(t, err) |
| 1308 | |
| 1309 | outgoingPacket := buffer.Bytes() |
| 1310 | reconstituted := packetToString(outgoingPacket) |
| 1311 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1312 | } |
| 1313 | |
| 1314 | func TestMibUploadNextRequestDecode(t *testing.T) { |
| 1315 | goodMessage := "02864e0a00020000003a00000000000000000000000000000000000000000000000000000000000000000028" |
| 1316 | data, err := stringToPacket(goodMessage) |
| 1317 | assert.NoError(t, err) |
| 1318 | |
| 1319 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1320 | assert.NotNil(t, packet) |
| 1321 | |
| 1322 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1323 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1324 | |
| 1325 | omciMsg, ok := omciLayer.(*OMCI) |
| 1326 | assert.True(t, ok) |
| 1327 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0286)) |
| 1328 | assert.Equal(t, omciMsg.MessageType, MibUploadNextRequestType) |
| 1329 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1330 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1331 | |
| 1332 | msgLayer := packet.Layer(LayerTypeMibUploadNextRequest) |
| 1333 | assert.NotNil(t, msgLayer) |
| 1334 | |
| 1335 | request, ok2 := msgLayer.(*MibUploadNextRequest) |
| 1336 | assert.True(t, ok2) |
| 1337 | assert.NotNil(t, request) |
| 1338 | assert.Equal(t, request.CommandSequenceNumber, uint16(0x3a)) |
| 1339 | |
| 1340 | // Verify string output for message |
| 1341 | packetString := packet.String() |
| 1342 | assert.NotZero(t, len(packetString)) |
| 1343 | } |
| 1344 | |
| 1345 | func TestMibUploadNextRequestSerialize(t *testing.T) { |
| 1346 | goodMessage := "02864e0a00020000003a00000000000000000000000000000000000000000000000000000000000000000028" |
| 1347 | |
| 1348 | omciLayer := &OMCI{ |
| 1349 | TransactionID: 0x0286, |
| 1350 | MessageType: MibUploadNextRequestType, |
| 1351 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1352 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1353 | } |
| 1354 | request := &MibUploadNextRequest{ |
| 1355 | MeBasePacket: MeBasePacket{ |
| 1356 | EntityClass: me.OnuDataClassID, |
| 1357 | EntityInstance: uint16(0), |
| 1358 | }, |
| 1359 | CommandSequenceNumber: uint16(0x3a), |
| 1360 | } |
| 1361 | // Test serialization back to former string |
| 1362 | var options gopacket.SerializeOptions |
| 1363 | options.FixLengths = true |
| 1364 | |
| 1365 | buffer := gopacket.NewSerializeBuffer() |
| 1366 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1367 | assert.NoError(t, err) |
| 1368 | |
| 1369 | outgoingPacket := buffer.Bytes() |
| 1370 | reconstituted := packetToString(outgoingPacket) |
| 1371 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1372 | } |
| 1373 | |
| 1374 | func TestMibUploadNextResponseDecode(t *testing.T) { |
| 1375 | goodMessage := "02862e0a0002000001150000fff0000000000000000000010100000000010000000000000000000000000028" |
| 1376 | data, err := stringToPacket(goodMessage) |
| 1377 | assert.NoError(t, err) |
| 1378 | |
| 1379 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1380 | assert.NotNil(t, packet) |
| 1381 | |
| 1382 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1383 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1384 | |
| 1385 | omciMsg, ok := omciLayer.(*OMCI) |
| 1386 | assert.True(t, ok) |
| 1387 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0286)) |
| 1388 | assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType) |
| 1389 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1390 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1391 | |
| 1392 | msgLayer := packet.Layer(LayerTypeMibUploadNextResponse) |
| 1393 | assert.NotNil(t, msgLayer) |
| 1394 | |
| 1395 | response, ok2 := msgLayer.(*MibUploadNextResponse) |
| 1396 | assert.True(t, ok2) |
| 1397 | assert.NotNil(t, response) |
| 1398 | assert.Equal(t, response.ReportedME.GetClassID(), me.PriorityQueueClassID) |
| 1399 | assert.Equal(t, response.ReportedME.GetEntityID(), uint16(0)) |
| 1400 | |
| 1401 | attributes := me.AttributeValueMap{ |
| 1402 | "QueueConfigurationOption": byte(0), |
| 1403 | "MaximumQueueSize": uint16(0), |
| 1404 | "AllocatedQueueSize": uint16(0), |
| 1405 | "DiscardBlockCounterResetInterval": uint16(0), |
| 1406 | "ThresholdValueForDiscardedBlocksDueToBufferOverflow": uint16(0), |
| 1407 | "RelatedPort": uint32(16842752), |
| 1408 | "TrafficSchedulerPointer": uint16(0), |
| 1409 | "Weight": byte(1), |
| 1410 | "BackPressureOperation": uint16(0), |
| 1411 | "BackPressureTime": uint32(0), |
| 1412 | "BackPressureOccurQueueThreshold": uint16(0), |
| 1413 | "BackPressureClearQueueThreshold": uint16(0), |
| 1414 | } |
| 1415 | for name, value := range attributes { |
| 1416 | pktValue, err := response.ReportedME.GetAttribute(name) |
| 1417 | assert.Nil(t, err) |
| 1418 | assert.Equal(t, pktValue, value) |
| 1419 | } |
| 1420 | // Verify string output for message |
| 1421 | packetString := packet.String() |
| 1422 | assert.NotZero(t, len(packetString)) |
| 1423 | } |
| 1424 | |
| 1425 | func TestMibUploadNextResponseSerialize(t *testing.T) { |
| 1426 | goodMessage := "02862e0a0002000001150000fff0000000000000000000010100000000010000000000000000000000000028" |
| 1427 | |
| 1428 | omciLayer := &OMCI{ |
| 1429 | TransactionID: 0x0286, |
| 1430 | MessageType: MibUploadNextResponseType, |
| 1431 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1432 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1433 | } |
| 1434 | paramData := me.ParamData{ |
| 1435 | EntityID: uint16(0), |
| 1436 | Attributes: me.AttributeValueMap{ |
| 1437 | "QueueConfigurationOption": byte(0), |
| 1438 | "MaximumQueueSize": uint16(0), |
| 1439 | "AllocatedQueueSize": uint16(0), |
| 1440 | "DiscardBlockCounterResetInterval": uint16(0), |
| 1441 | "ThresholdValueForDiscardedBlocksDueToBufferOverflow": uint16(0), |
| 1442 | "RelatedPort": uint32(16842752), |
| 1443 | "TrafficSchedulerPointer": uint16(0), |
| 1444 | "Weight": byte(1), |
| 1445 | "BackPressureOperation": uint16(0), |
| 1446 | "BackPressureTime": uint32(0), |
| 1447 | "BackPressureOccurQueueThreshold": uint16(0), |
| 1448 | "BackPressureClearQueueThreshold": uint16(0), |
| 1449 | }, |
| 1450 | } |
| 1451 | reportedME, err := me.NewPriorityQueue(paramData) |
| 1452 | assert.NotNil(t, err) |
| 1453 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1454 | |
| 1455 | request := &MibUploadNextResponse{ |
| 1456 | MeBasePacket: MeBasePacket{ |
| 1457 | EntityClass: me.OnuDataClassID, |
| 1458 | EntityInstance: uint16(0), |
| 1459 | }, |
| 1460 | ReportedME: *reportedME, |
| 1461 | } |
| 1462 | // Test serialization back to former string |
| 1463 | var options gopacket.SerializeOptions |
| 1464 | options.FixLengths = true |
| 1465 | |
| 1466 | buffer := gopacket.NewSerializeBuffer() |
| 1467 | omciErr := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1468 | assert.NoError(t, omciErr) |
| 1469 | |
| 1470 | outgoingPacket := buffer.Bytes() |
| 1471 | reconstituted := packetToString(outgoingPacket) |
| 1472 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1473 | } |
| 1474 | |
| 1475 | func TestMibUploadNextResponseBadCommandNumberDecode(t *testing.T) { |
| 1476 | // Test of a MIB Upload next Response that results when an invalid command number. |
| 1477 | // Note that if all attributes of a managed entity do not fit within one MIB |
| 1478 | // upload next response message, the attributes will be split over several |
| 1479 | // messages. The OLT can use the information in the attribute mask to determine |
| 1480 | // which attribute values are reported in which MIB upload next response message. |
| 1481 | //TODO: Implement |
| 1482 | } |
| 1483 | |
| 1484 | func TestMibUploadNextResponseBadCommandNumberSerialize(t *testing.T) { |
| 1485 | // Test of a MIB Upload next Response that results when an invalid command number |
| 1486 | // is requested. |
| 1487 | //TODO: Implement |
| 1488 | } |
| 1489 | |
| 1490 | // TODO: Create request/response tests for all of the following types |
| 1491 | //Test, |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1492 | // 1 2 3 4 |
| 1493 | // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 |
| 1494 | // 0004530a00070001ff000f424001000100000000000000000000000000000000000000000000000000000028 |
| 1495 | // 0004530a |
| 1496 | // 00070001 - ONU-G instance 0001 |
| 1497 | // ff - window size - 1 |
| 1498 | // 000f4240 - image size |
| 1499 | // 01 |
| 1500 | // 000100000000000000000000000000000000000000000000000000000028 |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1501 | func TestStartSoftwareDownloadRequestDecode(t *testing.T) { |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1502 | goodMessage := "0004530a00070001ff000f424001000100000000000000000000000000000000000000000000000000000028" |
| 1503 | data, err := stringToPacket(goodMessage) |
| 1504 | assert.NoError(t, err) |
| 1505 | |
| 1506 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1507 | assert.NotNil(t, packet) |
| 1508 | |
| 1509 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1510 | assert.NotNil(t, omciLayer) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1511 | |
| 1512 | omciMsg, ok := omciLayer.(*OMCI) |
| 1513 | assert.True(t, ok) |
| 1514 | assert.Equal(t, uint16(0x0004), omciMsg.TransactionID) |
| 1515 | assert.Equal(t, StartSoftwareDownloadRequestType, omciMsg.MessageType) |
| 1516 | assert.True(t, omciMsg.ResponseExpected) |
| 1517 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1518 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1519 | |
| 1520 | msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest) |
| 1521 | assert.NotNil(t, msgLayer) |
| 1522 | |
| 1523 | request, ok2 := msgLayer.(*StartSoftwareDownloadRequest) |
| 1524 | assert.True(t, ok2) |
| 1525 | assert.NotNil(t, request) |
| 1526 | assert.Equal(t, uint8(0xff), request.WindowSize) |
| 1527 | assert.Equal(t, uint32(0x000f4240), request.ImageSize) |
| 1528 | |
| 1529 | // Verify string output for message |
| 1530 | packetString := packet.String() |
| 1531 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | func TestStartSoftwareDownloadRequestSerialize(t *testing.T) { |
| 1535 | //// TODO: Need to complete implementation & debug this |
| 1536 | //goodMessage := "0000530a0007000113000f424001000100000000000000000000000000000000000000000000000000000028" |
| 1537 | // |
| 1538 | //omciLayer := &OMCI{ |
| 1539 | // TransactionID: 0x01, |
| 1540 | // MessageType: StartSoftwareDownloadRequestType, |
| 1541 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1542 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1543 | //} |
| 1544 | //request := &StartSoftwareDownloadRequest{ |
| 1545 | // MeBasePacket: MeBasePacket{ |
| 1546 | // EntityClass: OnuDataClassID, |
| 1547 | // // Default Instance ID is 0 |
| 1548 | // }, |
| 1549 | //} |
| 1550 | //// Test serialization back to former string |
| 1551 | //var options gopacket.SerializeOptions |
| 1552 | //options.FixLengths = true |
| 1553 | // |
| 1554 | //buffer := gopacket.NewSerializeBuffer() |
| 1555 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1556 | //assert.NoError(t, err) |
| 1557 | // |
| 1558 | //outgoingPacket := buffer.Bytes() |
| 1559 | //reconstituted := packetToString(outgoingPacket) |
| 1560 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1561 | } |
| 1562 | |
| 1563 | func TestStartSoftwareDownloadResponseDecode(t *testing.T) { |
| 1564 | // TODO: Need to complete implementation & debug this |
| 1565 | //goodMessage := "" |
| 1566 | //data, err := stringToPacket(goodMessage) |
| 1567 | //assert.NoError(t, err) |
| 1568 | // |
| 1569 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1570 | //assert.NotNil(t, packet) |
| 1571 | // |
| 1572 | //omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1573 | //assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1574 | // |
| 1575 | //omciMsg, ok := omciLayer.(*OMCI) |
| 1576 | //assert.True(t, ok) |
| 1577 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 1578 | //assert.Equal(t, omciMsg.MessageType, StartSoftwareDownloadResponseType) |
| 1579 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1580 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1581 | // |
| 1582 | //msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadResponse) |
| 1583 | // |
| 1584 | //assert.NotNil(t, msgLayer) |
| 1585 | // |
| 1586 | //response, ok2 := msgLayer.(*StartSoftwareDownloadResponse) |
| 1587 | //assert.True(t, ok2) |
| 1588 | //assert.NotNil(t, response) |
| 1589 | // |
| 1590 | //// Verify string output for message |
| 1591 | //packetString := packet.String() |
| 1592 | //assert.NotZero(t, len(packetString)) |
| 1593 | } |
| 1594 | |
| 1595 | func TestStartSoftwareDownloadResponseSerialize(t *testing.T) { |
| 1596 | // TODO: Need to complete implementation & debug this |
| 1597 | //goodMessage := "" |
| 1598 | // |
| 1599 | //omciLayer := &OMCI{ |
| 1600 | // TransactionID: 0x01, |
| 1601 | // MessageType: StartSoftwareDownloadResponseType, |
| 1602 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1603 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 1604 | //} |
| 1605 | //request := &StartSoftwareDownloadResponse{ |
| 1606 | // MeBasePacket: MeBasePacket{ |
| 1607 | // EntityClass: OnuDataClassID, |
| 1608 | // // Default Instance ID is 0 |
| 1609 | // }, |
| 1610 | //} |
| 1611 | //// Test serialization back to former string |
| 1612 | //var options gopacket.SerializeOptions |
| 1613 | //options.FixLengths = true |
| 1614 | // |
| 1615 | //buffer := gopacket.NewSerializeBuffer() |
| 1616 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1617 | //assert.NoError(t, err) |
| 1618 | // |
| 1619 | //outgoingPacket := buffer.Bytes() |
| 1620 | //reconstituted := packetToString(outgoingPacket) |
| 1621 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1622 | } |
| 1623 | |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1624 | // 1 2 3 4 |
| 1625 | // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 |
| 1626 | // 0008140a00070001 - Download section, AR=0 |
| 1627 | // cc - Section 0xcc |
| 1628 | // 01020304050607080910111213141516171819202122232425262728293031 |
| 1629 | // 00000028 |
| 1630 | |
| 1631 | func TestDownloadSectionRequestDecodeNoResponseExpected(t *testing.T) { |
| 1632 | goodMessage := "0008140a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1633 | data, err := stringToPacket(goodMessage) |
| 1634 | assert.NoError(t, err) |
| 1635 | |
| 1636 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1637 | assert.NotNil(t, packet) |
| 1638 | |
| 1639 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1640 | assert.NotNil(t, omciLayer) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1641 | |
| 1642 | omciMsg, ok := omciLayer.(*OMCI) |
| 1643 | assert.True(t, ok) |
| 1644 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 1645 | assert.Equal(t, DownloadSectionRequestType, omciMsg.MessageType) |
| 1646 | assert.False(t, omciMsg.ResponseExpected) |
| 1647 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1648 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1649 | |
| 1650 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 1651 | assert.NotNil(t, msgLayer) |
| 1652 | |
| 1653 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 1654 | assert.True(t, ok2) |
| 1655 | assert.NotNil(t, request) |
| 1656 | assert.Equal(t, uint8(0xcc), request.SectionNumber) |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1657 | assert.Equal(t, MaxDownloadSectionLength, len(request.SectionData)) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1658 | |
| 1659 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1660 | assert.Nil(t, genErr) |
| 1661 | assert.NotNil(t, sectionData) |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1662 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1663 | assert.Equal(t, sectionData, request.SectionData[:]) |
| 1664 | |
| 1665 | // Verify string output for message |
| 1666 | packetString := packet.String() |
| 1667 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1668 | } |
| 1669 | |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1670 | func TestDownloadSectionRequestDecodeResponseExpected(t *testing.T) { |
| 1671 | goodMessage := "0008540a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1672 | data, err := stringToPacket(goodMessage) |
| 1673 | assert.NoError(t, err) |
| 1674 | |
| 1675 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1676 | assert.NotNil(t, packet) |
| 1677 | |
| 1678 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1679 | assert.NotNil(t, omciLayer) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1680 | |
| 1681 | omciMsg, ok := omciLayer.(*OMCI) |
| 1682 | assert.True(t, ok) |
| 1683 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 1684 | assert.Equal(t, DownloadSectionRequestWithResponseType, omciMsg.MessageType) |
| 1685 | assert.True(t, omciMsg.ResponseExpected) |
| 1686 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1687 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1688 | |
| 1689 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 1690 | assert.NotNil(t, msgLayer) |
| 1691 | |
| 1692 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 1693 | assert.True(t, ok2) |
| 1694 | assert.NotNil(t, request) |
| 1695 | assert.Equal(t, uint8(0xcc), request.SectionNumber) |
| 1696 | assert.Equal(t, 31, len(request.SectionData)) |
| 1697 | |
| 1698 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1699 | assert.Nil(t, genErr) |
| 1700 | assert.NotNil(t, sectionData) |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1701 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1702 | assert.Equal(t, sectionData, request.SectionData[:]) |
| 1703 | |
| 1704 | // Verify string output for message |
| 1705 | packetString := packet.String() |
| 1706 | assert.NotZero(t, len(packetString)) |
| 1707 | } |
| 1708 | |
| 1709 | func TestDownloadSectionRequestSerializeNoResponseExpected(t *testing.T) { |
| 1710 | goodMessage := "0123140a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1711 | |
| 1712 | omciLayer := &OMCI{ |
| 1713 | TransactionID: 0x0123, |
| 1714 | MessageType: DownloadSectionRequestType, |
| 1715 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1716 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1717 | } |
| 1718 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1719 | assert.Nil(t, genErr) |
| 1720 | assert.NotNil(t, sectionData) |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1721 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1722 | |
| 1723 | request := &DownloadSectionRequest{ |
| 1724 | MeBasePacket: MeBasePacket{ |
| 1725 | EntityClass: me.SoftwareImageClassID, |
| 1726 | // Default Instance ID is 0 |
| 1727 | }, |
| 1728 | SectionNumber: 0xcc, |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1729 | SectionData: sectionData, |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1730 | } |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1731 | // Test serialization back to former string |
| 1732 | var options gopacket.SerializeOptions |
| 1733 | options.FixLengths = true |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1734 | |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1735 | buffer := gopacket.NewSerializeBuffer() |
| 1736 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1737 | assert.NoError(t, err) |
| 1738 | |
| 1739 | outgoingPacket := buffer.Bytes() |
| 1740 | reconstituted := packetToString(outgoingPacket) |
| 1741 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1742 | } |
| 1743 | |
| 1744 | func TestDownloadSectionRequestSerializeNoResponsePartialDataExpected(t *testing.T) { |
| 1745 | // If a small buffer is provided, serialize will now zero extend the baseline format |
| 1746 | goodMessage := "0123140a00070000cc0102030405060708091011121314151617181920212223242526272829000000000028" |
| 1747 | |
| 1748 | omciLayer := &OMCI{ |
| 1749 | TransactionID: 0x0123, |
| 1750 | MessageType: DownloadSectionRequestType, |
| 1751 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1752 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1753 | } |
| 1754 | sectionData, genErr := stringToPacket("0102030405060708091011121314151617181920212223242526272829") |
| 1755 | assert.Nil(t, genErr) |
| 1756 | assert.NotNil(t, sectionData) |
| 1757 | assert.Equal(t, MaxDownloadSectionLength-2, len(sectionData)) // Partial data buffer |
| 1758 | |
| 1759 | request := &DownloadSectionRequest{ |
| 1760 | MeBasePacket: MeBasePacket{ |
| 1761 | EntityClass: me.SoftwareImageClassID, |
| 1762 | // Default Instance ID is 0 |
| 1763 | }, |
| 1764 | SectionNumber: 0xcc, |
| 1765 | SectionData: sectionData, |
| 1766 | } |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1767 | // Test serialization back to former string |
| 1768 | var options gopacket.SerializeOptions |
| 1769 | options.FixLengths = true |
| 1770 | |
| 1771 | buffer := gopacket.NewSerializeBuffer() |
| 1772 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1773 | assert.NoError(t, err) |
| 1774 | |
| 1775 | outgoingPacket := buffer.Bytes() |
| 1776 | reconstituted := packetToString(outgoingPacket) |
| 1777 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1778 | } |
| 1779 | |
| 1780 | func TestDownloadSectionRequestSerializeResponseExpectedMethod1(t *testing.T) { |
| 1781 | goodMessage := "2468540a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1782 | |
| 1783 | omciLayer := &OMCI{ |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 1784 | TransactionID: 0x2468, |
| 1785 | MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1786 | ResponseExpected: true, |
| 1787 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1788 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1789 | } |
| 1790 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1791 | assert.Nil(t, genErr) |
| 1792 | assert.NotNil(t, sectionData) |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1793 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1794 | |
| 1795 | request := &DownloadSectionRequest{ |
| 1796 | MeBasePacket: MeBasePacket{ |
| 1797 | EntityClass: me.SoftwareImageClassID, |
| 1798 | // Default Instance ID is 0 |
| 1799 | }, |
| 1800 | SectionNumber: 0xcc, |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1801 | SectionData: sectionData, |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1802 | } |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1803 | // Test serialization back to former string |
| 1804 | var options gopacket.SerializeOptions |
| 1805 | options.FixLengths = true |
| 1806 | |
| 1807 | buffer := gopacket.NewSerializeBuffer() |
| 1808 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1809 | assert.NoError(t, err) |
| 1810 | |
| 1811 | outgoingPacket := buffer.Bytes() |
| 1812 | reconstituted := packetToString(outgoingPacket) |
| 1813 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1814 | } |
| 1815 | |
| 1816 | func TestDownloadSectionRequestSerializeResponseExpectedMethod2(t *testing.T) { |
| 1817 | goodMessage := "2468540a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 1818 | |
| 1819 | // In this case, just use the request type with AR response requested already encoded |
| 1820 | omciLayer := &OMCI{ |
| 1821 | TransactionID: 0x2468, |
| 1822 | MessageType: DownloadSectionRequestWithResponseType, |
| 1823 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1824 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1825 | } |
| 1826 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 1827 | assert.Nil(t, genErr) |
| 1828 | assert.NotNil(t, sectionData) |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1829 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1830 | |
| 1831 | request := &DownloadSectionRequest{ |
| 1832 | MeBasePacket: MeBasePacket{ |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 1833 | EntityClass: me.SoftwareImageClassID, |
| 1834 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1835 | }, |
| 1836 | SectionNumber: 0xcc, |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 1837 | SectionData: sectionData, |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1838 | } |
Chip Boling | 8c8018e | 2021-02-22 15:56:00 -0600 | [diff] [blame] | 1839 | // Test serialization back to former string |
| 1840 | var options gopacket.SerializeOptions |
| 1841 | options.FixLengths = true |
| 1842 | |
| 1843 | buffer := gopacket.NewSerializeBuffer() |
| 1844 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1845 | assert.NoError(t, err) |
| 1846 | |
| 1847 | outgoingPacket := buffer.Bytes() |
| 1848 | reconstituted := packetToString(outgoingPacket) |
| 1849 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | func TestDownloadSectionResponseDecode(t *testing.T) { |
Chip Boling | 588d970 | 2021-02-26 09:48:07 -0600 | [diff] [blame] | 1853 | goodMessage := "0022340a00070001061f00000000000000000000000000000000000000000000000000000000000000000028" |
| 1854 | data, err := stringToPacket(goodMessage) |
| 1855 | assert.NoError(t, err) |
| 1856 | |
| 1857 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1858 | assert.NotNil(t, packet) |
| 1859 | |
| 1860 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1861 | assert.NotNil(t, omciLayer) |
Chip Boling | 588d970 | 2021-02-26 09:48:07 -0600 | [diff] [blame] | 1862 | |
| 1863 | omciMsg, ok := omciLayer.(*OMCI) |
| 1864 | assert.True(t, ok) |
| 1865 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0022)) |
| 1866 | assert.Equal(t, omciMsg.MessageType, DownloadSectionResponseType) |
| 1867 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1868 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1869 | |
| 1870 | msgLayer := packet.Layer(LayerTypeDownloadSectionResponse) |
| 1871 | |
| 1872 | assert.NotNil(t, msgLayer) |
| 1873 | |
| 1874 | response, ok2 := msgLayer.(*DownloadSectionResponse) |
| 1875 | assert.True(t, ok2) |
| 1876 | assert.NotNil(t, response) |
| 1877 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 1878 | assert.Equal(t, byte(0x1f), response.SectionNumber) |
| 1879 | |
| 1880 | // Verify string output for message |
| 1881 | packetString := packet.String() |
| 1882 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | func TestDownloadSectionResponseSerialize(t *testing.T) { |
Chip Boling | 588d970 | 2021-02-26 09:48:07 -0600 | [diff] [blame] | 1886 | goodMessage := "0022340a00070001061f00000000000000000000000000000000000000000000000000000000000000000028" |
| 1887 | |
| 1888 | omciLayer := &OMCI{ |
| 1889 | TransactionID: 0x0022, |
| 1890 | MessageType: DownloadSectionResponseType, |
| 1891 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1892 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1893 | } |
| 1894 | request := &DownloadSectionResponse{ |
| 1895 | MeBasePacket: MeBasePacket{ |
| 1896 | EntityClass: me.SoftwareImageClassID, |
| 1897 | EntityInstance: 1, |
| 1898 | }, |
| 1899 | Result: me.DeviceBusy, |
| 1900 | SectionNumber: 0x1f, |
| 1901 | } |
| 1902 | // Test serialization back to former string |
| 1903 | var options gopacket.SerializeOptions |
| 1904 | options.FixLengths = true |
| 1905 | |
| 1906 | buffer := gopacket.NewSerializeBuffer() |
| 1907 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1908 | assert.NoError(t, err) |
| 1909 | |
| 1910 | outgoingPacket := buffer.Bytes() |
| 1911 | reconstituted := packetToString(outgoingPacket) |
| 1912 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | func TestEndSoftwareDownloadRequestDecode(t *testing.T) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1916 | // |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 1917 | // 8100 55 0a 0007 0001 ff92a226 000f4240 01 0001 00000000000000000000000000000000000000000000000028 |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1918 | // |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 1919 | goodMessage := "8100550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028" |
| 1920 | data, err := stringToPacket(goodMessage) |
| 1921 | assert.NoError(t, err) |
| 1922 | |
| 1923 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1924 | assert.NotNil(t, packet) |
| 1925 | |
| 1926 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1927 | assert.NotNil(t, omciLayer) |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 1928 | |
| 1929 | omciMsg, ok := omciLayer.(*OMCI) |
| 1930 | assert.True(t, ok) |
| 1931 | assert.Equal(t, omciMsg.TransactionID, uint16(0x8100)) |
| 1932 | assert.Equal(t, omciMsg.MessageType, EndSoftwareDownloadRequestType) |
| 1933 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1934 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1935 | |
| 1936 | msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadRequest) |
| 1937 | assert.NotNil(t, msgLayer) |
| 1938 | |
| 1939 | request, ok2 := msgLayer.(*EndSoftwareDownloadRequest) |
| 1940 | assert.True(t, ok2) |
| 1941 | assert.NotNil(t, request) |
| 1942 | assert.Equal(t, uint32(0xff92a226), request.CRC32) |
| 1943 | assert.Equal(t, uint32(0x000f4240), request.ImageSize) |
| 1944 | assert.Equal(t, byte(1), request.NumberOfInstances) |
| 1945 | assert.Equal(t, 1, len(request.ImageInstances)) |
| 1946 | assert.Equal(t, uint16(1), request.ImageInstances[0]) |
| 1947 | |
| 1948 | // Verify string output for message |
| 1949 | packetString := packet.String() |
| 1950 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | func TestEndSoftwareDownloadRequestSerialize(t *testing.T) { |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 1954 | // 8100 55 0a 0007 0001 ff92a226 000f4240 01 0001 00000000000000000000000000000000000000000000000028 |
| 1955 | goodMessage := "8100550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028" |
| 1956 | |
| 1957 | omciLayer := &OMCI{ |
| 1958 | TransactionID: 0x8100, |
| 1959 | MessageType: EndSoftwareDownloadRequestType, |
| 1960 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1961 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1962 | } |
| 1963 | request := &EndSoftwareDownloadRequest{ |
| 1964 | MeBasePacket: MeBasePacket{ |
| 1965 | EntityClass: me.SoftwareImageClassID, |
| 1966 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
| 1967 | }, |
| 1968 | CRC32: 0xff92a226, |
| 1969 | ImageSize: 1000000, |
| 1970 | NumberOfInstances: 1, |
| 1971 | ImageInstances: []uint16{1}, |
| 1972 | } |
| 1973 | // Test serialization back to former string |
| 1974 | var options gopacket.SerializeOptions |
| 1975 | options.FixLengths = true |
| 1976 | |
| 1977 | buffer := gopacket.NewSerializeBuffer() |
| 1978 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1979 | assert.NoError(t, err) |
| 1980 | |
| 1981 | outgoingPacket := buffer.Bytes() |
| 1982 | reconstituted := packetToString(outgoingPacket) |
| 1983 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | func TestEndSoftwareDownloadResponseDecode(t *testing.T) { |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 1987 | // 8123 35 0a 0007 0001 06 0000000000000000000000000000000000000000000000000000000000000000000028 |
| 1988 | goodMessage := "8123350a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 1989 | data, err := stringToPacket(goodMessage) |
| 1990 | assert.NoError(t, err) |
| 1991 | |
| 1992 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1993 | assert.NotNil(t, packet) |
| 1994 | |
| 1995 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 1996 | assert.NotNil(t, omciLayer) |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 1997 | |
| 1998 | omciMsg, ok := omciLayer.(*OMCI) |
| 1999 | assert.True(t, ok) |
| 2000 | assert.Equal(t, omciMsg.TransactionID, uint16(0x8123)) |
| 2001 | assert.Equal(t, omciMsg.MessageType, EndSoftwareDownloadResponseType) |
| 2002 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2003 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2004 | |
| 2005 | msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadResponse) |
| 2006 | assert.NotNil(t, msgLayer) |
| 2007 | |
| 2008 | response, ok2 := msgLayer.(*EndSoftwareDownloadResponse) |
| 2009 | assert.True(t, ok2) |
| 2010 | assert.NotNil(t, response) |
| 2011 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 2012 | assert.Equal(t, byte(0), response.NumberOfInstances) |
| 2013 | assert.Nil(t, response.MeResults) |
| 2014 | |
| 2015 | // Verify string output for message |
| 2016 | packetString := packet.String() |
| 2017 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | func TestEndSoftwareDownloadResponseSerialize(t *testing.T) { |
Chip Boling | 2ccec85 | 2021-02-24 11:18:02 -0600 | [diff] [blame] | 2021 | goodMessage := "8456350a00070000010000000000000000000000000000000000000000000000000000000000000000000028" |
| 2022 | |
| 2023 | omciLayer := &OMCI{ |
| 2024 | TransactionID: 0x8456, |
| 2025 | MessageType: EndSoftwareDownloadResponseType, |
| 2026 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2027 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2028 | } |
| 2029 | request := &EndSoftwareDownloadResponse{ |
| 2030 | MeBasePacket: MeBasePacket{ |
| 2031 | EntityClass: me.SoftwareImageClassID, |
| 2032 | // Default is zero |
| 2033 | }, |
| 2034 | Result: me.ProcessingError, |
| 2035 | NumberOfInstances: 0, |
| 2036 | } |
| 2037 | // Test serialization back to former string |
| 2038 | var options gopacket.SerializeOptions |
| 2039 | options.FixLengths = true |
| 2040 | |
| 2041 | buffer := gopacket.NewSerializeBuffer() |
| 2042 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2043 | assert.NoError(t, err) |
| 2044 | |
| 2045 | outgoingPacket := buffer.Bytes() |
| 2046 | reconstituted := packetToString(outgoingPacket) |
| 2047 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | func TestActivateSoftwareRequestDecode(t *testing.T) { |
| 2051 | // TODO: Need to complete implementation & debug this |
| 2052 | //goodMessage := "0000560a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2053 | //data, err := stringToPacket(goodMessage) |
| 2054 | //assert.NoError(t, err) |
| 2055 | // |
| 2056 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2057 | //assert.NotNil(t, packet) |
| 2058 | // |
| 2059 | //omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2060 | //assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2061 | // |
| 2062 | //omciMsg, ok := omciLayer.(*OMCI) |
| 2063 | //assert.True(t, ok) |
| 2064 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2065 | //assert.Equal(t, omciMsg.MessageType, ActivateSoftwareRequestType) |
| 2066 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2067 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2068 | // |
| 2069 | //msgLayer := packet.Layer(LayerTypeActivateSoftwareRequest) |
| 2070 | //assert.NotNil(t, msgLayer) |
| 2071 | // |
| 2072 | //request, ok2 := msgLayer.(*ActivateSoftwareRequest) |
| 2073 | //assert.True(t, ok2) |
| 2074 | //assert.NotNil(t, request) |
| 2075 | // |
| 2076 | //// Verify string output for message |
| 2077 | //packetString := packet.String() |
| 2078 | //assert.NotZero(t, len(packetString)) |
| 2079 | } |
| 2080 | |
| 2081 | func TestActivateSoftwareRequestSerialize(t *testing.T) { |
| 2082 | // TODO: Need to complete implementation & debug this |
| 2083 | //goodMessage := "0000560a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2084 | // |
| 2085 | //omciLayer := &OMCI{ |
| 2086 | // TransactionID: 0x01, |
| 2087 | // MessageType: ActivateSoftwareRequestType, |
| 2088 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2089 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 2090 | //} |
| 2091 | //request := &ActivateSoftwareRequest{ |
| 2092 | // MeBasePacket: MeBasePacket{ |
| 2093 | // EntityClass: OnuDataClassID, |
| 2094 | // // Default Instance ID is 0 |
| 2095 | // }, |
| 2096 | //} |
| 2097 | //// Test serialization back to former string |
| 2098 | //var options gopacket.SerializeOptions |
| 2099 | //options.FixLengths = true |
| 2100 | // |
| 2101 | //buffer := gopacket.NewSerializeBuffer() |
| 2102 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2103 | //assert.NoError(t, err) |
| 2104 | // |
| 2105 | //outgoingPacket := buffer.Bytes() |
| 2106 | //reconstituted := packetToString(outgoingPacket) |
| 2107 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2108 | } |
| 2109 | |
| 2110 | func TestActivateSoftwareResponseDecode(t *testing.T) { |
| 2111 | // TODO: Need to complete implementation & debug this |
| 2112 | //goodMessage := "" |
| 2113 | //data, err := stringToPacket(goodMessage) |
| 2114 | //assert.NoError(t, err) |
| 2115 | // |
| 2116 | //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2117 | //assert.NotNil(t, packet) |
| 2118 | // |
| 2119 | //omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2120 | //assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2121 | // |
| 2122 | //omciMsg, ok := omciLayer.(*OMCI) |
| 2123 | //assert.True(t, ok) |
| 2124 | //assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2125 | //assert.Equal(t, omciMsg.MessageType, ActivateSoftwareResponseType) |
| 2126 | //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2127 | //assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2128 | // |
| 2129 | //msgLayer := packet.Layer(LayerTypeActivateSoftwareResponse) |
| 2130 | // |
| 2131 | //assert.NotNil(t, msgLayer) |
| 2132 | // |
| 2133 | //response, ok2 := msgLayer.(*ActivateSoftwareResponse) |
| 2134 | //assert.True(t, ok2) |
| 2135 | //assert.NotNil(t, response) |
| 2136 | // |
| 2137 | //// Verify string output for message |
| 2138 | //packetString := packet.String() |
| 2139 | //assert.NotZero(t, len(packetString)) |
| 2140 | } |
| 2141 | |
| 2142 | func TestActivateSoftwareResponseSerialize(t *testing.T) { |
| 2143 | // TODO: Need to complete implementation & debug this |
| 2144 | //goodMessage := "" |
| 2145 | // |
| 2146 | //omciLayer := &OMCI{ |
| 2147 | // TransactionID: 0x01, |
| 2148 | // MessageType: ActivateSoftwareResponseType, |
| 2149 | // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2150 | // // Length: 0x28, // Optional, defaults to 40 octets |
| 2151 | //} |
| 2152 | //request := &ActivateSoftwareResponse{ |
| 2153 | // MeBasePacket: MeBasePacket{ |
| 2154 | // EntityClass: OnuDataClassID, |
| 2155 | // // Default Instance ID is 0 |
| 2156 | // }, |
| 2157 | //} |
| 2158 | //// Test serialization back to former string |
| 2159 | //var options gopacket.SerializeOptions |
| 2160 | //options.FixLengths = true |
| 2161 | // |
| 2162 | //buffer := gopacket.NewSerializeBuffer() |
| 2163 | //err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2164 | //assert.NoError(t, err) |
| 2165 | // |
| 2166 | //outgoingPacket := buffer.Bytes() |
| 2167 | //reconstituted := packetToString(outgoingPacket) |
| 2168 | //assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2169 | } |
| 2170 | |
| 2171 | func TestCommitSoftwareRequestDecode(t *testing.T) { |
Chip Boling | 58fc4d2 | 2021-03-10 13:23:53 -0600 | [diff] [blame] | 2172 | goodMessage := "0011570a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2173 | data, err := stringToPacket(goodMessage) |
| 2174 | assert.NoError(t, err) |
| 2175 | |
| 2176 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2177 | assert.NotNil(t, packet) |
| 2178 | |
| 2179 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2180 | assert.NotNil(t, omciLayer) |
Chip Boling | 58fc4d2 | 2021-03-10 13:23:53 -0600 | [diff] [blame] | 2181 | |
| 2182 | omciMsg, ok := omciLayer.(*OMCI) |
| 2183 | assert.True(t, ok) |
| 2184 | assert.Equal(t, omciMsg.TransactionID, uint16(0x11)) |
| 2185 | assert.Equal(t, omciMsg.MessageType, CommitSoftwareRequestType) |
| 2186 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2187 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2188 | |
| 2189 | msgLayer := packet.Layer(LayerTypeCommitSoftwareRequest) |
| 2190 | assert.NotNil(t, msgLayer) |
| 2191 | |
| 2192 | request, ok2 := msgLayer.(*CommitSoftwareRequest) |
| 2193 | assert.True(t, ok2) |
| 2194 | assert.NotNil(t, request) |
| 2195 | assert.Equal(t, uint16(1), request.MeBasePacket.EntityInstance) |
| 2196 | |
| 2197 | // Verify string output for message |
| 2198 | packetString := packet.String() |
| 2199 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | func TestCommitSoftwareRequestSerialize(t *testing.T) { |
Chip Boling | 58fc4d2 | 2021-03-10 13:23:53 -0600 | [diff] [blame] | 2203 | goodMessage := "0044570a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2204 | |
| 2205 | omciLayer := &OMCI{ |
| 2206 | TransactionID: 0x44, |
| 2207 | MessageType: CommitSoftwareRequestType, |
| 2208 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2209 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2210 | } |
| 2211 | request := &CommitSoftwareRequest{ |
| 2212 | MeBasePacket: MeBasePacket{ |
| 2213 | EntityClass: me.SoftwareImageClassID, |
| 2214 | EntityInstance: 1, // Default Instance ID is 0 |
| 2215 | }, |
| 2216 | } |
| 2217 | // Test serialization back to former string |
| 2218 | var options gopacket.SerializeOptions |
| 2219 | options.FixLengths = true |
| 2220 | |
| 2221 | buffer := gopacket.NewSerializeBuffer() |
| 2222 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2223 | assert.NoError(t, err) |
| 2224 | |
| 2225 | outgoingPacket := buffer.Bytes() |
| 2226 | reconstituted := packetToString(outgoingPacket) |
| 2227 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | func TestCommitSoftwareResponseDecode(t *testing.T) { |
Chip Boling | 58fc4d2 | 2021-03-10 13:23:53 -0600 | [diff] [blame] | 2231 | goodMessage := "00aa370a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 2232 | data, err := stringToPacket(goodMessage) |
| 2233 | assert.NoError(t, err) |
| 2234 | |
| 2235 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2236 | assert.NotNil(t, packet) |
| 2237 | |
| 2238 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2239 | assert.NotNil(t, omciLayer) |
Chip Boling | 58fc4d2 | 2021-03-10 13:23:53 -0600 | [diff] [blame] | 2240 | |
| 2241 | omciMsg, ok := omciLayer.(*OMCI) |
| 2242 | assert.True(t, ok) |
| 2243 | assert.Equal(t, omciMsg.TransactionID, uint16(0xaa)) |
| 2244 | assert.Equal(t, omciMsg.MessageType, CommitSoftwareResponseType) |
| 2245 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2246 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2247 | |
| 2248 | msgLayer := packet.Layer(LayerTypeCommitSoftwareResponse) |
| 2249 | |
| 2250 | assert.NotNil(t, msgLayer) |
| 2251 | |
| 2252 | response, ok2 := msgLayer.(*CommitSoftwareResponse) |
| 2253 | assert.True(t, ok2) |
| 2254 | assert.NotNil(t, response) |
| 2255 | assert.Equal(t, uint16(1), response.MeBasePacket.EntityInstance) |
| 2256 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 2257 | |
| 2258 | // Verify string output for message |
| 2259 | packetString := packet.String() |
| 2260 | assert.NotZero(t, len(packetString)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | func TestCommitSoftwareResponseSerialize(t *testing.T) { |
Chip Boling | 58fc4d2 | 2021-03-10 13:23:53 -0600 | [diff] [blame] | 2264 | goodMessage := "8001370a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 2265 | |
| 2266 | omciLayer := &OMCI{ |
| 2267 | TransactionID: 0x8001, |
| 2268 | MessageType: CommitSoftwareResponseType, |
| 2269 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2270 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2271 | } |
| 2272 | request := &CommitSoftwareResponse{ |
| 2273 | MeBasePacket: MeBasePacket{ |
| 2274 | EntityClass: me.SoftwareImageClassID, |
| 2275 | EntityInstance: 1, // Default Instance ID is 0 |
| 2276 | }, |
| 2277 | Result: me.DeviceBusy, |
| 2278 | } |
| 2279 | // Test serialization back to former string |
| 2280 | var options gopacket.SerializeOptions |
| 2281 | options.FixLengths = true |
| 2282 | |
| 2283 | buffer := gopacket.NewSerializeBuffer() |
| 2284 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2285 | assert.NoError(t, err) |
| 2286 | |
| 2287 | outgoingPacket := buffer.Bytes() |
| 2288 | reconstituted := packetToString(outgoingPacket) |
| 2289 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | func TestMibResetResponseDecode(t *testing.T) { |
| 2293 | goodMessage := "00012F0A00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2294 | data, err := stringToPacket(goodMessage) |
| 2295 | assert.NoError(t, err) |
| 2296 | |
| 2297 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2298 | assert.NotNil(t, packet) |
| 2299 | |
| 2300 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2301 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2302 | |
| 2303 | omciMsg, ok := omciLayer.(*OMCI) |
| 2304 | assert.True(t, ok) |
| 2305 | assert.Equal(t, omciMsg.MessageType, MibResetResponseType) |
| 2306 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2307 | |
| 2308 | msgLayer := packet.Layer(LayerTypeMibResetResponse) |
| 2309 | |
| 2310 | assert.NotNil(t, msgLayer) |
| 2311 | |
| 2312 | response, ok2 := msgLayer.(*MibResetResponse) |
| 2313 | assert.True(t, ok2) |
| 2314 | assert.NotNil(t, response) |
| 2315 | |
| 2316 | // Verify string output for message |
| 2317 | packetString := packet.String() |
| 2318 | assert.NotZero(t, len(packetString)) |
| 2319 | } |
| 2320 | |
| 2321 | func TestMibResetResponseSerialize(t *testing.T) { |
| 2322 | goodMessage := "00012F0A00020000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2323 | |
| 2324 | omciLayer := &OMCI{ |
| 2325 | TransactionID: 0x01, |
| 2326 | MessageType: MibResetResponseType, |
| 2327 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2328 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2329 | } |
| 2330 | request := &MibResetResponse{ |
| 2331 | MeBasePacket: MeBasePacket{ |
| 2332 | EntityClass: me.OnuDataClassID, |
| 2333 | // Default Instance ID is 0 |
| 2334 | }, |
| 2335 | } |
| 2336 | // Test serialization back to former string |
| 2337 | var options gopacket.SerializeOptions |
| 2338 | options.FixLengths = true |
| 2339 | |
| 2340 | buffer := gopacket.NewSerializeBuffer() |
| 2341 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2342 | assert.NoError(t, err) |
| 2343 | |
| 2344 | outgoingPacket := buffer.Bytes() |
| 2345 | reconstituted := packetToString(outgoingPacket) |
| 2346 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2347 | } |
| 2348 | |
| 2349 | func TestSynchronizeTimeRequestDecode(t *testing.T) { |
| 2350 | goodMessage := "0109580a0100000007e20c0101301b0000000000000000000000000000000000000000000000000000000028" |
| 2351 | data, err := stringToPacket(goodMessage) |
| 2352 | assert.NoError(t, err) |
| 2353 | |
| 2354 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2355 | assert.NotNil(t, packet) |
| 2356 | |
| 2357 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2358 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2359 | |
| 2360 | omciMsg, ok := omciLayer.(*OMCI) |
| 2361 | assert.True(t, ok) |
| 2362 | assert.Equal(t, omciMsg.MessageType, SynchronizeTimeRequestType) |
| 2363 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2364 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2365 | |
| 2366 | msgLayer := packet.Layer(LayerTypeSynchronizeTimeRequest) |
| 2367 | assert.NotNil(t, msgLayer) |
| 2368 | |
| 2369 | request, ok2 := msgLayer.(*SynchronizeTimeRequest) |
| 2370 | assert.True(t, ok2) |
| 2371 | assert.NotNil(t, request) |
| 2372 | assert.Equal(t, request.Year, uint16(2018)) |
| 2373 | assert.Equal(t, request.Month, uint8(12)) |
| 2374 | assert.Equal(t, request.Day, uint8(1)) |
| 2375 | assert.Equal(t, request.Hour, uint8(01)) |
| 2376 | assert.Equal(t, request.Minute, uint8(48)) |
| 2377 | assert.Equal(t, request.Second, uint8(27)) |
| 2378 | |
| 2379 | // Verify string output for message |
| 2380 | packetString := packet.String() |
| 2381 | assert.NotZero(t, len(packetString)) |
| 2382 | } |
| 2383 | |
| 2384 | func TestSynchronizeTimeRequestSerialize(t *testing.T) { |
| 2385 | goodMessage := "0109580a0100000007e20c0101301b0000000000000000000000000000000000000000000000000000000028" |
| 2386 | |
| 2387 | omciLayer := &OMCI{ |
| 2388 | TransactionID: 0x0109, |
| 2389 | MessageType: SynchronizeTimeRequestType, |
| 2390 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2391 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2392 | } |
| 2393 | request := &SynchronizeTimeRequest{ |
| 2394 | MeBasePacket: MeBasePacket{ |
| 2395 | EntityClass: me.OnuGClassID, |
| 2396 | // Default Instance ID is 0 |
| 2397 | }, |
| 2398 | Year: uint16(2018), |
| 2399 | Month: uint8(12), |
| 2400 | Day: uint8(1), |
| 2401 | Hour: uint8(01), |
| 2402 | Minute: uint8(48), |
| 2403 | Second: uint8(27), |
| 2404 | } |
| 2405 | // Test serialization back to former string |
| 2406 | var options gopacket.SerializeOptions |
| 2407 | options.FixLengths = true |
| 2408 | |
| 2409 | buffer := gopacket.NewSerializeBuffer() |
| 2410 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2411 | assert.NoError(t, err) |
| 2412 | |
| 2413 | outgoingPacket := buffer.Bytes() |
| 2414 | reconstituted := packetToString(outgoingPacket) |
| 2415 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2416 | } |
| 2417 | |
| 2418 | func TestSynchronizeTimeResponseDecode(t *testing.T) { |
| 2419 | goodMessage := "0109380a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2420 | data, err := stringToPacket(goodMessage) |
| 2421 | assert.NoError(t, err) |
| 2422 | |
| 2423 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2424 | assert.NotNil(t, packet) |
| 2425 | |
| 2426 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2427 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2428 | |
| 2429 | omciMsg, ok := omciLayer.(*OMCI) |
| 2430 | assert.True(t, ok) |
| 2431 | assert.Equal(t, omciMsg.MessageType, SynchronizeTimeResponseType) |
| 2432 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2433 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2434 | |
| 2435 | msgLayer := packet.Layer(LayerTypeSynchronizeTimeResponse) |
| 2436 | assert.NotNil(t, msgLayer) |
| 2437 | |
| 2438 | response, ok2 := msgLayer.(*SynchronizeTimeResponse) |
| 2439 | assert.True(t, ok2) |
| 2440 | assert.NotNil(t, response) |
| 2441 | |
| 2442 | // Verify string output for message |
| 2443 | packetString := packet.String() |
| 2444 | assert.NotZero(t, len(packetString)) |
| 2445 | } |
| 2446 | |
| 2447 | func TestSynchronizeTimeResponseSerialize(t *testing.T) { |
| 2448 | goodMessage := "0109380a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2449 | |
| 2450 | omciLayer := &OMCI{ |
| 2451 | TransactionID: 0x0109, |
| 2452 | MessageType: SynchronizeTimeResponseType, |
| 2453 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2454 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2455 | } |
| 2456 | request := &SynchronizeTimeResponse{ |
| 2457 | MeBasePacket: MeBasePacket{ |
| 2458 | EntityClass: me.OnuGClassID, |
| 2459 | EntityInstance: uint16(0), |
| 2460 | }, |
| 2461 | Result: me.Success, |
| 2462 | SuccessResults: uint8(0), |
| 2463 | } |
| 2464 | // Test serialization back to former string |
| 2465 | var options gopacket.SerializeOptions |
| 2466 | options.FixLengths = true |
| 2467 | |
| 2468 | buffer := gopacket.NewSerializeBuffer() |
| 2469 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2470 | assert.NoError(t, err) |
| 2471 | |
| 2472 | outgoingPacket := buffer.Bytes() |
| 2473 | reconstituted := packetToString(outgoingPacket) |
| 2474 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2475 | } |
| 2476 | |
| 2477 | func TestRebootRequestDecode(t *testing.T) { |
| 2478 | goodMessage := "0001590a01000000010000000000000000000000000000000000000000000000000000000000000000000028" |
| 2479 | data, err := stringToPacket(goodMessage) |
| 2480 | assert.NoError(t, err) |
| 2481 | |
| 2482 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2483 | assert.NotNil(t, packet) |
| 2484 | |
| 2485 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2486 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2487 | |
| 2488 | omciMsg, ok := omciLayer.(*OMCI) |
| 2489 | assert.True(t, ok) |
| 2490 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0001)) |
| 2491 | assert.Equal(t, omciMsg.MessageType, RebootRequestType) |
| 2492 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2493 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2494 | |
| 2495 | msgLayer := packet.Layer(LayerTypeRebootRequest) |
| 2496 | assert.NotNil(t, msgLayer) |
| 2497 | |
| 2498 | request, ok2 := msgLayer.(*RebootRequest) |
| 2499 | assert.True(t, ok2) |
| 2500 | assert.NotNil(t, request) |
| 2501 | assert.Equal(t, request.EntityClass, me.OnuGClassID) |
| 2502 | assert.Equal(t, request.EntityInstance, uint16(0)) |
| 2503 | assert.Equal(t, request.RebootCondition, uint8(1)) |
| 2504 | |
| 2505 | // Verify string output for message |
| 2506 | packetString := packet.String() |
| 2507 | assert.NotZero(t, len(packetString)) |
| 2508 | } |
| 2509 | |
| 2510 | func TestRebootRequestSerialize(t *testing.T) { |
| 2511 | goodMessage := "0001590a01000000020000000000000000000000000000000000000000000000000000000000000000000028" |
| 2512 | |
| 2513 | omciLayer := &OMCI{ |
| 2514 | TransactionID: 0x0001, |
| 2515 | MessageType: RebootRequestType, |
| 2516 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2517 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2518 | } |
| 2519 | request := &RebootRequest{ |
| 2520 | MeBasePacket: MeBasePacket{ |
| 2521 | EntityClass: me.OnuGClassID, |
| 2522 | // Default Instance ID is 0 |
| 2523 | }, |
| 2524 | RebootCondition: uint8(2), |
| 2525 | } |
| 2526 | // Test serialization back to former string |
| 2527 | var options gopacket.SerializeOptions |
| 2528 | options.FixLengths = true |
| 2529 | |
| 2530 | buffer := gopacket.NewSerializeBuffer() |
| 2531 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2532 | assert.NoError(t, err) |
| 2533 | |
| 2534 | outgoingPacket := buffer.Bytes() |
| 2535 | reconstituted := packetToString(outgoingPacket) |
| 2536 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2537 | } |
| 2538 | |
| 2539 | func TestRebootResponseDecode(t *testing.T) { |
| 2540 | goodMessage := "023c390a01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 2541 | data, err := stringToPacket(goodMessage) |
| 2542 | assert.NoError(t, err) |
| 2543 | |
| 2544 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2545 | assert.NotNil(t, packet) |
| 2546 | |
| 2547 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2548 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2549 | |
| 2550 | omciMsg, ok := omciLayer.(*OMCI) |
| 2551 | assert.True(t, ok) |
| 2552 | assert.Equal(t, omciMsg.TransactionID, uint16(0x023c)) |
| 2553 | assert.Equal(t, omciMsg.MessageType, RebootResponseType) |
| 2554 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2555 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2556 | |
| 2557 | msgLayer := packet.Layer(LayerTypeRebootResponse) |
| 2558 | assert.NotNil(t, msgLayer) |
| 2559 | |
| 2560 | response, ok2 := msgLayer.(*RebootResponse) |
| 2561 | assert.True(t, ok2) |
| 2562 | assert.NotNil(t, response) |
| 2563 | assert.Equal(t, response.EntityClass, me.OnuGClassID) |
| 2564 | assert.Equal(t, response.EntityInstance, uint16(0)) |
| 2565 | assert.Equal(t, response.Result, me.Success) |
| 2566 | |
| 2567 | // Verify string output for message |
| 2568 | packetString := packet.String() |
| 2569 | assert.NotZero(t, len(packetString)) |
| 2570 | } |
| 2571 | |
| 2572 | func TestRebootResponseSerialize(t *testing.T) { |
| 2573 | goodMessage := "023c390a01000000060000000000000000000000000000000000000000000000000000000000000000000028" |
| 2574 | |
| 2575 | omciLayer := &OMCI{ |
| 2576 | TransactionID: 0x023c, |
| 2577 | MessageType: RebootResponseType, |
| 2578 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2579 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2580 | } |
| 2581 | request := &RebootResponse{ |
| 2582 | MeBasePacket: MeBasePacket{ |
| 2583 | EntityClass: me.OnuGClassID, |
| 2584 | EntityInstance: uint16(0), |
| 2585 | }, |
| 2586 | Result: me.DeviceBusy, |
| 2587 | } |
| 2588 | // Test serialization back to former string |
| 2589 | var options gopacket.SerializeOptions |
| 2590 | options.FixLengths = true |
| 2591 | |
| 2592 | buffer := gopacket.NewSerializeBuffer() |
| 2593 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2594 | assert.NoError(t, err) |
| 2595 | |
| 2596 | outgoingPacket := buffer.Bytes() |
| 2597 | reconstituted := packetToString(outgoingPacket) |
| 2598 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2599 | } |
| 2600 | |
| 2601 | func TestGetNextRequestDecode(t *testing.T) { |
| 2602 | goodMessage := "285e5a0a00ab0202040000010000000000000000000000000000000000000000000000000000000000000028" |
| 2603 | data, err := stringToPacket(goodMessage) |
| 2604 | assert.NoError(t, err) |
| 2605 | |
| 2606 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2607 | assert.NotNil(t, packet) |
| 2608 | |
| 2609 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2610 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2611 | |
| 2612 | omciMsg, ok := omciLayer.(*OMCI) |
| 2613 | assert.True(t, ok) |
| 2614 | assert.Equal(t, omciMsg.TransactionID, uint16(0x285e)) |
| 2615 | assert.Equal(t, omciMsg.MessageType, GetNextRequestType) |
| 2616 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2617 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2618 | |
| 2619 | msgLayer := packet.Layer(LayerTypeGetNextRequest) |
| 2620 | assert.NotNil(t, msgLayer) |
| 2621 | |
| 2622 | request, ok2 := msgLayer.(*GetNextRequest) |
| 2623 | assert.True(t, ok2) |
| 2624 | assert.NotNil(t, request) |
| 2625 | assert.Equal(t, request.EntityClass, me.ExtendedVlanTaggingOperationConfigurationDataClassID) |
| 2626 | assert.Equal(t, request.EntityInstance, uint16(0x0202)) |
| 2627 | assert.Equal(t, request.AttributeMask, uint16(0x0400)) |
| 2628 | assert.Equal(t, request.SequenceNumber, uint16(1)) |
| 2629 | |
| 2630 | // Verify string output for message |
| 2631 | packetString := packet.String() |
| 2632 | assert.NotZero(t, len(packetString)) |
| 2633 | } |
| 2634 | |
| 2635 | func TestGetNextRequestSerialize(t *testing.T) { |
| 2636 | goodMessage := "285e5a0a00ab0202040000010000000000000000000000000000000000000000000000000000000000000028" |
| 2637 | |
| 2638 | omciLayer := &OMCI{ |
| 2639 | TransactionID: 0x285e, |
| 2640 | MessageType: GetNextRequestType, |
| 2641 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2642 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2643 | } |
| 2644 | request := &GetNextRequest{ |
| 2645 | MeBasePacket: MeBasePacket{ |
| 2646 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 2647 | EntityInstance: uint16(0x0202), |
| 2648 | }, |
| 2649 | AttributeMask: uint16(0x0400), |
| 2650 | SequenceNumber: uint16(1), |
| 2651 | } |
| 2652 | // Test serialization back to former string |
| 2653 | var options gopacket.SerializeOptions |
| 2654 | options.FixLengths = true |
| 2655 | |
| 2656 | buffer := gopacket.NewSerializeBuffer() |
| 2657 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2658 | assert.NoError(t, err) |
| 2659 | |
| 2660 | outgoingPacket := buffer.Bytes() |
| 2661 | reconstituted := packetToString(outgoingPacket) |
| 2662 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2663 | } |
| 2664 | |
| 2665 | func TestGetNextResponseDecode(t *testing.T) { |
| 2666 | goodMessage := "285e3a0a00ab0202000400080334000000000000000000000000000000000000000000000000000000000028" |
| 2667 | |
| 2668 | data, err := stringToPacket(goodMessage) |
| 2669 | assert.NoError(t, err) |
| 2670 | |
| 2671 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2672 | assert.NotNil(t, packet) |
| 2673 | |
| 2674 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2675 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2676 | |
| 2677 | omciMsg, ok := omciLayer.(*OMCI) |
| 2678 | assert.True(t, ok) |
| 2679 | assert.Equal(t, omciMsg.TransactionID, uint16(0x285e)) |
| 2680 | assert.Equal(t, omciMsg.MessageType, GetNextResponseType) |
| 2681 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2682 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2683 | |
| 2684 | msgLayer := packet.Layer(LayerTypeGetNextResponse) |
| 2685 | assert.NotNil(t, msgLayer) |
| 2686 | |
| 2687 | vlanOpTable := []byte{0x08, 0x03, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2688 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 2689 | |
| 2690 | response, ok2 := msgLayer.(*GetNextResponse) |
| 2691 | assert.True(t, ok2) |
| 2692 | assert.NotNil(t, response) |
| 2693 | assert.Equal(t, me.ExtendedVlanTaggingOperationConfigurationDataClassID, response.EntityClass) |
| 2694 | assert.Equal(t, uint16(0x0202), response.EntityInstance) |
| 2695 | assert.Equal(t, me.Success, response.Result) |
| 2696 | assert.Equal(t, uint16(0x0400), response.AttributeMask) |
| 2697 | |
| 2698 | // For GetNextResponse frames, caller is responsible for trimming last packet to remaining |
| 2699 | // size |
| 2700 | expectedOctets := 16 |
| 2701 | value := response.Attributes["ReceivedFrameVlanTaggingOperationTable"] |
| 2702 | assert.Equal(t, vlanOpTable, value.([]byte)[:expectedOctets]) |
| 2703 | |
| 2704 | // Verify string output for message |
| 2705 | packetString := packet.String() |
| 2706 | assert.NotZero(t, len(packetString)) |
| 2707 | } |
| 2708 | |
| 2709 | func TestGetNextResponseSerialize(t *testing.T) { |
| 2710 | goodMessage := "285e3a0a00ab0202000400080334000000000000000000000000000000000000000000000000000000000028" |
| 2711 | |
| 2712 | omciLayer := &OMCI{ |
| 2713 | TransactionID: 0x285e, |
| 2714 | MessageType: GetNextResponseType, |
| 2715 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2716 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2717 | } |
| 2718 | vlanOpTable := []byte{0x08, 0x03, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2719 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 2720 | |
| 2721 | request := &GetNextResponse{ |
| 2722 | MeBasePacket: MeBasePacket{ |
| 2723 | EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID, |
| 2724 | EntityInstance: uint16(0x0202), |
| 2725 | }, |
| 2726 | Result: me.Success, |
| 2727 | AttributeMask: uint16(0x0400), |
| 2728 | Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": vlanOpTable}, |
| 2729 | } |
| 2730 | // Test serialization back to former string |
| 2731 | var options gopacket.SerializeOptions |
| 2732 | options.FixLengths = true |
| 2733 | |
| 2734 | buffer := gopacket.NewSerializeBuffer() |
| 2735 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2736 | assert.NoError(t, err) |
| 2737 | |
| 2738 | outgoingPacket := buffer.Bytes() |
| 2739 | reconstituted := packetToString(outgoingPacket) |
| 2740 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2741 | } |
| 2742 | |
Chip Boling | f73bf3e | 2021-06-01 08:43:52 -0500 | [diff] [blame] | 2743 | // TODO: Create request/response tests for all of the following types -> SetTable |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2744 | |
| 2745 | func TestAlarmNotificationDecode(t *testing.T) { |
| 2746 | goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2747 | data, err := stringToPacket(goodMessage) |
| 2748 | assert.NoError(t, err) |
| 2749 | |
| 2750 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2751 | assert.NotNil(t, packet) |
| 2752 | |
| 2753 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2754 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2755 | |
| 2756 | omciMsg, ok := omciLayer.(*OMCI) |
| 2757 | assert.True(t, ok) |
| 2758 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2759 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2760 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2761 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2762 | |
| 2763 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2764 | assert.NotNil(t, msgLayer) |
| 2765 | |
| 2766 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2767 | assert.True(t, ok2) |
| 2768 | assert.NotNil(t, request) |
| 2769 | assert.Equal(t, request.EntityClass, me.PhysicalPathTerminationPointEthernetUniClassID) |
| 2770 | assert.Equal(t, request.EntityInstance, uint16(0x104)) |
| 2771 | assert.Equal(t, request.AlarmBitmap, [28]byte{ |
| 2772 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2773 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2774 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2775 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2776 | }) |
| 2777 | assert.Equal(t, request.AlarmSequenceNumber, byte(5)) |
| 2778 | |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 2779 | // Active/Clear tests |
| 2780 | active, err2 := request.IsAlarmActive(0) |
| 2781 | clear, err3 := request.IsAlarmClear(0) |
| 2782 | assert.Nil(t, err2) |
| 2783 | assert.Nil(t, err3) |
| 2784 | assert.True(t, active) |
| 2785 | assert.False(t, clear) |
| 2786 | |
| 2787 | // Active/Clear for undefined alarm bits |
| 2788 | active, err2 = request.IsAlarmActive(1) |
| 2789 | clear, err3 = request.IsAlarmClear(1) |
| 2790 | assert.NotNil(t, err2) |
| 2791 | assert.NotNil(t, err3) |
| 2792 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2793 | // Verify string output for message |
| 2794 | packetString := packet.String() |
| 2795 | assert.NotZero(t, len(packetString)) |
| 2796 | } |
| 2797 | |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 2798 | func TestInvalidClassAlarmNotificationDecode(t *testing.T) { |
| 2799 | // Choosing GalEthernetProfile (272) since it does not support alarms, show we should |
| 2800 | // file the decode |
| 2801 | badMessage := "0000100a01100104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2802 | data, err := stringToPacket(badMessage) |
| 2803 | assert.NoError(t, err) |
| 2804 | |
| 2805 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2806 | assert.NotNil(t, packet) |
| 2807 | |
| 2808 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2809 | assert.NotNil(t, omciLayer) |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 2810 | |
| 2811 | omciMsg, ok := omciLayer.(*OMCI) |
| 2812 | assert.True(t, ok) |
| 2813 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2814 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2815 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2816 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2817 | |
| 2818 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2819 | assert.Nil(t, msgLayer) |
| 2820 | |
| 2821 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2822 | assert.False(t, ok2) |
| 2823 | assert.Nil(t, request) |
| 2824 | } |
| 2825 | |
| 2826 | func TestUnknownsMeAlarmNotificationDecode(t *testing.T) { |
| 2827 | // Choosing class ID 22 since it is in the G.988 class ID space and is reserved |
| 2828 | goodMessage := "0000100a00160104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2829 | data, err := stringToPacket(goodMessage) |
| 2830 | assert.NoError(t, err) |
| 2831 | |
| 2832 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2833 | assert.NotNil(t, packet) |
| 2834 | |
| 2835 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2836 | assert.NotNil(t, omciLayer) |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 2837 | |
| 2838 | omciMsg, ok := omciLayer.(*OMCI) |
| 2839 | assert.True(t, ok) |
| 2840 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2841 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2842 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2843 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2844 | |
| 2845 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2846 | assert.NotNil(t, msgLayer) |
| 2847 | |
| 2848 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2849 | assert.True(t, ok2) |
| 2850 | assert.NotNil(t, request) |
| 2851 | assert.Equal(t, request.EntityClass, me.ClassID(22)) |
| 2852 | assert.Equal(t, request.EntityInstance, uint16(0x104)) |
| 2853 | assert.Equal(t, request.AlarmBitmap, [28]byte{ |
| 2854 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2855 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2856 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2857 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2858 | }) |
| 2859 | assert.Equal(t, request.AlarmSequenceNumber, byte(5)) |
| 2860 | } |
| 2861 | |
| 2862 | func TestVendorSpecificAlarmNotificationDecode(t *testing.T) { |
| 2863 | // Choosing class ID 255 since it is in the first vendor specific class ID space |
| 2864 | goodMessage := "0000100a00FF0104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2865 | data, err := stringToPacket(goodMessage) |
| 2866 | assert.NoError(t, err) |
| 2867 | |
| 2868 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2869 | assert.NotNil(t, packet) |
| 2870 | |
| 2871 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2872 | assert.NotNil(t, omciLayer) |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 2873 | |
| 2874 | omciMsg, ok := omciLayer.(*OMCI) |
| 2875 | assert.True(t, ok) |
| 2876 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2877 | assert.Equal(t, omciMsg.MessageType, AlarmNotificationType) |
| 2878 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2879 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2880 | |
| 2881 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 2882 | assert.NotNil(t, msgLayer) |
| 2883 | |
| 2884 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 2885 | assert.True(t, ok2) |
| 2886 | assert.NotNil(t, request) |
| 2887 | assert.Equal(t, request.EntityClass, me.ClassID(255)) |
| 2888 | assert.Equal(t, request.EntityInstance, uint16(0x104)) |
| 2889 | assert.Equal(t, request.AlarmBitmap, [28]byte{ |
| 2890 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2891 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2892 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2893 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2894 | }) |
| 2895 | assert.Equal(t, request.AlarmSequenceNumber, byte(5)) |
| 2896 | } |
| 2897 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2898 | func TestAlarmNotificationSerialize(t *testing.T) { |
| 2899 | goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028" |
| 2900 | |
| 2901 | omciLayer := &OMCI{ |
| 2902 | TransactionID: 0, |
| 2903 | MessageType: AlarmNotificationType, |
| 2904 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2905 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2906 | } |
| 2907 | request := &AlarmNotificationMsg{ |
| 2908 | MeBasePacket: MeBasePacket{ |
| 2909 | EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 2910 | EntityInstance: uint16(0x104), |
| 2911 | }, |
| 2912 | AlarmBitmap: [28]byte{ |
| 2913 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2914 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2915 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2916 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2917 | }, |
| 2918 | AlarmSequenceNumber: byte(5), |
| 2919 | } |
| 2920 | // Test serialization back to former string |
| 2921 | var options gopacket.SerializeOptions |
| 2922 | options.FixLengths = true |
| 2923 | |
| 2924 | buffer := gopacket.NewSerializeBuffer() |
| 2925 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2926 | assert.NoError(t, err) |
| 2927 | |
| 2928 | outgoingPacket := buffer.Bytes() |
| 2929 | reconstituted := packetToString(outgoingPacket) |
| 2930 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2931 | } |
| 2932 | |
| 2933 | func TestAttributeValueChangeDecode(t *testing.T) { |
| 2934 | goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028" |
| 2935 | data, err := stringToPacket(goodMessage) |
| 2936 | assert.NoError(t, err) |
| 2937 | |
| 2938 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 2939 | assert.NotNil(t, packet) |
| 2940 | |
| 2941 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 2942 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 2943 | |
| 2944 | omciMsg, ok := omciLayer.(*OMCI) |
| 2945 | assert.True(t, ok) |
| 2946 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0)) |
| 2947 | assert.Equal(t, omciMsg.MessageType, AttributeValueChangeType) |
| 2948 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 2949 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 2950 | |
| 2951 | msgLayer := packet.Layer(LayerTypeAttributeValueChange) |
| 2952 | assert.NotNil(t, msgLayer) |
| 2953 | |
| 2954 | request, ok2 := msgLayer.(*AttributeValueChangeMsg) |
| 2955 | assert.True(t, ok2) |
| 2956 | assert.NotNil(t, request) |
| 2957 | assert.Equal(t, request.AttributeMask, uint16(0x8000)) |
| 2958 | assert.Equal(t, request.EntityClass, me.SoftwareImageClassID) |
| 2959 | assert.Equal(t, request.EntityInstance, uint16(0)) |
| 2960 | assert.Equal(t, request.Attributes["Version"], []byte{ |
| 2961 | 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36, |
| 2962 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) |
| 2963 | |
| 2964 | // Verify string output for message |
| 2965 | packetString := packet.String() |
| 2966 | assert.NotZero(t, len(packetString)) |
| 2967 | } |
| 2968 | |
| 2969 | func TestAttributeValueChangeSerialize(t *testing.T) { |
| 2970 | goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028" |
| 2971 | |
| 2972 | omciLayer := &OMCI{ |
| 2973 | TransactionID: 0, |
| 2974 | MessageType: AttributeValueChangeType, |
| 2975 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 2976 | // Length: 0x28, // Optional, defaults to 40 octets |
| 2977 | } |
| 2978 | request := &AttributeValueChangeMsg{ |
| 2979 | MeBasePacket: MeBasePacket{ |
| 2980 | EntityClass: me.SoftwareImageClassID, |
| 2981 | EntityInstance: uint16(0), |
| 2982 | }, |
| 2983 | AttributeMask: uint16(0x8000), |
| 2984 | Attributes: me.AttributeValueMap{ |
| 2985 | "Version": []byte{ |
| 2986 | 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36, |
| 2987 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2988 | }, |
| 2989 | }, |
| 2990 | } |
| 2991 | // Test serialization back to former string |
| 2992 | var options gopacket.SerializeOptions |
| 2993 | options.FixLengths = true |
| 2994 | |
| 2995 | buffer := gopacket.NewSerializeBuffer() |
| 2996 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2997 | assert.NoError(t, err) |
| 2998 | |
| 2999 | outgoingPacket := buffer.Bytes() |
| 3000 | reconstituted := packetToString(outgoingPacket) |
| 3001 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3002 | } |
| 3003 | |
Chip Boling | 4e0ac9a | 2021-01-20 14:23:09 -0600 | [diff] [blame] | 3004 | func TestJira3769(t *testing.T) { |
| 3005 | // VOL-3769. Error parsing get response with processing error and large mask |
| 3006 | sampleMessage := "035e290a0101000001FFFC000000000000000000000000000000000000000000000000000000000000000028" |
| 3007 | data, err := stringToPacket(sampleMessage) |
| 3008 | assert.NoError(t, err) |
| 3009 | |
| 3010 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3011 | assert.NotNil(t, packet) |
| 3012 | |
| 3013 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3014 | assert.NotNil(t, omciLayer) |
| 3015 | |
| 3016 | omciMsg, ok := omciLayer.(*OMCI) |
| 3017 | assert.True(t, ok) |
| 3018 | assert.Equal(t, omciMsg.TransactionID, uint16(0x035e)) |
| 3019 | assert.Equal(t, omciMsg.MessageType, GetResponseType) |
| 3020 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 3021 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 3022 | |
| 3023 | // before bugfix for this JIRA, the following call returned 'nil' Failure was |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 3024 | // occurring before this at during getResponse decoding. |
Chip Boling | 4e0ac9a | 2021-01-20 14:23:09 -0600 | [diff] [blame] | 3025 | msgLayer := packet.Layer(LayerTypeGetResponse) |
| 3026 | assert.NotNil(t, msgLayer) |
| 3027 | |
| 3028 | response, ok2 := msgLayer.(*GetResponse) |
| 3029 | assert.True(t, ok2) |
| 3030 | assert.NotNil(t, response) |
| 3031 | assert.Equal(t, response.Result, me.ProcessingError) |
| 3032 | assert.Equal(t, response.AttributeMask, uint16(0xFFFC)) |
| 3033 | } |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 3034 | |
Chip Boling | 2c046fa | 2021-02-23 11:30:29 -0600 | [diff] [blame] | 3035 | func TestJira3863(t *testing.T) { |
| 3036 | goodMessage := "81a9240a013880010700000000000000000000000000000000000000000000000000000000000000000000283f73ddea" |
| 3037 | data, err := stringToPacket(goodMessage) |
| 3038 | assert.NoError(t, err) |
| 3039 | |
| 3040 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3041 | assert.NotNil(t, packet) |
| 3042 | |
| 3043 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 3044 | assert.NotNil(t, omciLayer) |
Chip Boling | 2c046fa | 2021-02-23 11:30:29 -0600 | [diff] [blame] | 3045 | |
| 3046 | omciMsg, ok := omciLayer.(*OMCI) |
| 3047 | assert.True(t, ok) |
| 3048 | assert.NotNil(t, omciMsg) |
| 3049 | |
| 3050 | msgLayer := packet.Layer(LayerTypeCreateResponse) |
| 3051 | assert.NotNil(t, msgLayer) |
| 3052 | |
| 3053 | // FEC PM ME not in class map so the following was failing (ok2 false) |
| 3054 | response, ok2 := msgLayer.(*CreateResponse) |
| 3055 | assert.True(t, ok2) |
| 3056 | assert.NotNil(t, response) |
| 3057 | |
| 3058 | // Verify string output for message |
| 3059 | packetString := packet.String() |
| 3060 | assert.NotZero(t, len(packetString)) |
| 3061 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 3062 | |
| 3063 | func TestExtendedGetRequestDecode(t *testing.T) { |
| 3064 | //ONU-2G: 257 |
| 3065 | goodMessage := "035e490b010100000002fffc" |
| 3066 | data, err := stringToPacket(goodMessage) |
| 3067 | assert.NoError(t, err) |
| 3068 | |
| 3069 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3070 | assert.NotNil(t, packet) |
| 3071 | |
| 3072 | omciLayer := packet.Layer(LayerTypeOMCI) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 3073 | assert.NotNil(t, omciLayer) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 3074 | |
| 3075 | omciMsg, ok := omciLayer.(*OMCI) |
| 3076 | assert.True(t, ok) |
| 3077 | assert.Equal(t, omciMsg.TransactionID, uint16(0x035e)) |
| 3078 | assert.Equal(t, omciMsg.MessageType, GetRequestType) |
| 3079 | assert.Equal(t, omciMsg.DeviceIdentifier, ExtendedIdent) |
| 3080 | assert.Equal(t, omciMsg.Length, uint16(2)) |
| 3081 | |
| 3082 | msgLayer := packet.Layer(LayerTypeGetRequest) |
| 3083 | assert.NotNil(t, msgLayer) |
| 3084 | |
| 3085 | request, ok2 := msgLayer.(*GetRequest) |
| 3086 | assert.True(t, ok2) |
| 3087 | assert.NotNil(t, request) |
| 3088 | |
| 3089 | //ONU-2G: 257 |
| 3090 | assert.Equal(t, me.Onu2GClassID, request.EntityClass) |
| 3091 | assert.Equal(t, uint16(0), request.EntityInstance) |
| 3092 | assert.Equal(t, uint16(0xfffc), request.AttributeMask) |
| 3093 | |
| 3094 | // Verify string output for message |
| 3095 | packetString := packet.String() |
| 3096 | assert.NotZero(t, len(packetString)) |
| 3097 | } |
| 3098 | |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 3099 | func TestExtendedGetRequestDecodeTruncated(t *testing.T) { |
| 3100 | goodMessage := "035e490b010100000002ff" |
| 3101 | data, err := stringToPacket(goodMessage) |
| 3102 | assert.NoError(t, err) |
| 3103 | |
| 3104 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3105 | assert.NotNil(t, packet) |
| 3106 | |
| 3107 | failure := packet.ErrorLayer() |
| 3108 | assert.NotNil(t, failure) |
| 3109 | |
| 3110 | decodeFailure, ok := failure.(*gopacket.DecodeFailure) |
| 3111 | assert.NotNil(t, decodeFailure) |
| 3112 | assert.True(t, ok) |
| 3113 | assert.NotNil(t, decodeFailure.String()) |
| 3114 | assert.True(t, len(decodeFailure.String()) > 0) |
| 3115 | |
| 3116 | metadata := packet.Metadata() |
| 3117 | assert.NotNil(t, metadata) |
| 3118 | assert.True(t, metadata.Truncated) |
| 3119 | |
| 3120 | // Verify string output for message |
| 3121 | packetString := packet.String() |
| 3122 | assert.NotZero(t, len(packetString)) |
| 3123 | } |
| 3124 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 3125 | func TestExtendedGetRequestSerialize(t *testing.T) { |
| 3126 | goodMessage := "035e490b010100000002fffc" |
| 3127 | |
| 3128 | omciLayer := &OMCI{ |
| 3129 | TransactionID: 0x035e, |
| 3130 | MessageType: GetRequestType, |
| 3131 | DeviceIdentifier: ExtendedIdent, |
| 3132 | // Length parameter is optional for Extended message format serialization |
| 3133 | // and if present it will be overwritten during the serialization with the |
| 3134 | // actual value. |
| 3135 | } |
| 3136 | request := &GetRequest{ |
| 3137 | MeBasePacket: MeBasePacket{ |
| 3138 | EntityClass: me.Onu2GClassID, |
| 3139 | EntityInstance: uint16(0), |
| 3140 | Extended: true, |
| 3141 | }, |
| 3142 | AttributeMask: uint16(0xfffc), |
| 3143 | } |
| 3144 | // Test serialization back to former string |
| 3145 | var options gopacket.SerializeOptions |
| 3146 | options.FixLengths = true |
| 3147 | |
| 3148 | buffer := gopacket.NewSerializeBuffer() |
| 3149 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3150 | assert.NoError(t, err) |
| 3151 | |
| 3152 | outgoingPacket := buffer.Bytes() |
| 3153 | reconstituted := packetToString(outgoingPacket) |
| 3154 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3155 | } |
| 3156 | |
| 3157 | func TestExtendedGetResponseDecode(t *testing.T) { |
| 3158 | attrDef, omciErr := me.GetAttributesDefinitions(me.Onu2GClassID) |
| 3159 | assert.NotNil(t, attrDef) |
| 3160 | assert.NotNil(t, omciErr) |
| 3161 | assert.Equal(t, omciErr.StatusCode(), me.Success) |
| 3162 | |
| 3163 | attributes := []interface{}{ |
| 3164 | toOctets("AAAAAAAAAAAAAAAAAAAAAAAAAAA="), // 1: MultiByteField - "EquipmentId" (20 zeros) |
| 3165 | byte(0xb4), // 2: ByteField - "OpticalNetworkUnitManagementAndControlChannelOmccVersion" |
| 3166 | uint16(0x1234), // 3: Uint16Field - "VendorProductCode" |
| 3167 | byte(1), // 4: ByteField - "SecurityCapability" |
| 3168 | byte(1), // 5: ByteField - "SecurityMode" |
| 3169 | uint16(0x5678), // 6: Uint16Field - "TotalPriorityQueueNumber" |
| 3170 | byte(0x44), // 7: ByteField - "TotalTrafficSchedulerNumber" |
| 3171 | byte(1), // 8: ByteField - "Deprecated" |
| 3172 | uint16(0x55aa), // 9: Uint16Field - "TotalGemPortIdNumber" |
| 3173 | uint32(0xC4108011), // 10: Uint32Field - "Sysuptime" |
| 3174 | uint16(0x6), // 11: Uint16Field - "ConnectivityCapability" |
| 3175 | byte(6), // 12: ByteField - "CurrentConnectivityMode" |
| 3176 | uint16(2), // 13: Uint16Field - "QualityOfServiceQosConfigurationFlexibility" |
| 3177 | uint16(0x1234), // 14: Uint16Field - "PriorityQueueScaleFactor" |
| 3178 | } |
| 3179 | attributeData := make([]byte, 0) |
| 3180 | |
| 3181 | // Walk through all attributes and encode them |
| 3182 | for _, value := range attributes { |
| 3183 | //attrDef, err := meDef.GetAttributeByIndex(index) |
| 3184 | var buf []byte |
| 3185 | u8, ok := value.(byte) |
| 3186 | if ok { |
| 3187 | buf = []byte{u8} |
| 3188 | } else { |
| 3189 | u16, ok := value.(uint16) |
| 3190 | if ok { |
| 3191 | buf = make([]byte, 2) |
| 3192 | binary.BigEndian.PutUint16(buf, u16) |
| 3193 | } else { |
| 3194 | u32, ok := value.(uint32) |
| 3195 | if ok { |
| 3196 | buf = make([]byte, 4) |
| 3197 | binary.BigEndian.PutUint32(buf, u32) |
| 3198 | } else { |
| 3199 | bytes, ok := value.([]byte) |
| 3200 | if ok { |
| 3201 | buf = bytes |
| 3202 | } else { |
| 3203 | assert.True(t, false) // Unknown attribute type |
| 3204 | } |
| 3205 | } |
| 3206 | } |
| 3207 | } |
| 3208 | attributeData = append(attributeData, buf...) |
| 3209 | } |
| 3210 | attributeMask := 0xfffc |
| 3211 | msgLength := len(attributeData) + 7 |
| 3212 | // Results is 0 ("00"), and the two optional attribute masks are 0 ("00000000") as well |
| 3213 | goodMessage := "035e290b01010000" + fmt.Sprintf("%04x", msgLength) + |
| 3214 | "00" + fmt.Sprintf("%04x", attributeMask) + "00000000" + packetToString(attributeData) |
| 3215 | |
| 3216 | data, err := stringToPacket(goodMessage) |
| 3217 | assert.NotNil(t, data) |
| 3218 | assert.Nil(t, err) |
| 3219 | |
| 3220 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3221 | assert.NotNil(t, packet) |
| 3222 | |
| 3223 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3224 | assert.NotNil(t, omciLayer) |
| 3225 | |
| 3226 | omciMsg, ok := omciLayer.(*OMCI) |
| 3227 | assert.True(t, ok) |
| 3228 | assert.Equal(t, omciMsg.TransactionID, uint16(0x035e)) |
| 3229 | assert.Equal(t, omciMsg.MessageType, GetResponseType) |
| 3230 | assert.Equal(t, omciMsg.DeviceIdentifier, ExtendedIdent) |
| 3231 | assert.Equal(t, omciMsg.Length, uint16(msgLength)) |
| 3232 | |
| 3233 | msgLayer := packet.Layer(LayerTypeGetResponse) |
| 3234 | assert.NotNil(t, msgLayer) |
| 3235 | |
| 3236 | response, ok2 := msgLayer.(*GetResponse) |
| 3237 | assert.True(t, ok2) |
| 3238 | assert.NotNil(t, response) |
| 3239 | assert.Equal(t, response.Result, me.Success) |
| 3240 | assert.Equal(t, response.AttributeMask, uint16(attributeMask)) |
| 3241 | assert.Equal(t, response.FailedAttributeMask, uint16(0)) |
| 3242 | assert.Equal(t, response.UnsupportedAttributeMask, uint16(0)) |
| 3243 | |
| 3244 | assert.Equal(t, response.Attributes["EquipmentId"], toOctets("AAAAAAAAAAAAAAAAAAAAAAAAAAA=")) |
| 3245 | assert.Equal(t, response.Attributes["OpticalNetworkUnitManagementAndControlChannelOmccVersion"], byte(0xb4)) // ) |
| 3246 | assert.Equal(t, response.Attributes["VendorProductCode"], uint16(0x1234)) |
| 3247 | assert.Equal(t, response.Attributes["SecurityCapability"], byte(1)) |
| 3248 | assert.Equal(t, response.Attributes["SecurityMode"], byte(1)) |
| 3249 | assert.Equal(t, response.Attributes["TotalPriorityQueueNumber"], uint16(0x5678)) |
| 3250 | assert.Equal(t, response.Attributes["TotalTrafficSchedulerNumber"], byte(0x44)) |
| 3251 | assert.Equal(t, response.Attributes["Deprecated"], byte(1)) |
| 3252 | assert.Equal(t, response.Attributes["TotalGemPortIdNumber"], uint16(0x55aa)) |
| 3253 | assert.Equal(t, response.Attributes["Sysuptime"], uint32(0xC4108011)) |
| 3254 | assert.Equal(t, response.Attributes["ConnectivityCapability"], uint16(0x6)) |
| 3255 | assert.Equal(t, response.Attributes["CurrentConnectivityMode"], byte(6)) |
| 3256 | assert.Equal(t, response.Attributes["QualityOfServiceQosConfigurationFlexibility"], uint16(2)) |
| 3257 | assert.Equal(t, response.Attributes["PriorityQueueScaleFactor"], uint16(0x1234)) |
| 3258 | |
| 3259 | // Verify string output for message |
| 3260 | packetString := packet.String() |
| 3261 | assert.NotZero(t, len(packetString)) |
| 3262 | } |
| 3263 | |
| 3264 | func TestExtendedGetResponseSerialize(t *testing.T) { |
| 3265 | goodMessage := "035e290b01010000003100fffc" + |
| 3266 | "000000000000000000000000000000000000000000000000" + |
| 3267 | "b4123401015678440155aac410801100060600021234" |
| 3268 | |
| 3269 | omciLayer := &OMCI{ |
| 3270 | TransactionID: 0x035e, |
| 3271 | MessageType: GetResponseType, |
| 3272 | DeviceIdentifier: ExtendedIdent, |
| 3273 | // Length parameter is optional for Extended message format serialization |
| 3274 | // and if present it will be overwritten during the serialization with the |
| 3275 | // actual value. |
| 3276 | } |
| 3277 | request := &GetResponse{ |
| 3278 | MeBasePacket: MeBasePacket{ |
| 3279 | EntityClass: me.Onu2GClassID, |
| 3280 | EntityInstance: uint16(0), |
| 3281 | Extended: true, |
| 3282 | }, |
| 3283 | Result: 0, |
| 3284 | AttributeMask: uint16(0xfffc), |
| 3285 | Attributes: me.AttributeValueMap{ |
| 3286 | "EquipmentId": toOctets("AAAAAAAAAAAAAAAAAAAAAAAAAAA="), |
| 3287 | "OpticalNetworkUnitManagementAndControlChannelOmccVersion": byte(0xb4), |
| 3288 | "VendorProductCode": uint16(0x1234), |
| 3289 | "SecurityCapability": byte(1), |
| 3290 | "SecurityMode": byte(1), |
| 3291 | "TotalPriorityQueueNumber": uint16(0x5678), |
| 3292 | "TotalTrafficSchedulerNumber": byte(0x44), |
| 3293 | "Deprecated": byte(1), |
| 3294 | "TotalGemPortIdNumber": uint16(0x55aa), |
| 3295 | "Sysuptime": uint32(0xC4108011), |
| 3296 | "ConnectivityCapability": uint16(0x6), |
| 3297 | "CurrentConnectivityMode": byte(6), |
| 3298 | "QualityOfServiceQosConfigurationFlexibility": uint16(2), |
| 3299 | "PriorityQueueScaleFactor": uint16(0x1234), |
| 3300 | }, |
| 3301 | } |
| 3302 | // Test serialization back to former string |
| 3303 | var options gopacket.SerializeOptions |
| 3304 | options.FixLengths = true |
| 3305 | |
| 3306 | buffer := gopacket.NewSerializeBuffer() |
| 3307 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3308 | assert.NoError(t, err) |
| 3309 | |
| 3310 | outgoingPacket := buffer.Bytes() |
| 3311 | reconstituted := packetToString(outgoingPacket) |
| 3312 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3313 | } |
| 3314 | |
Chip Boling | 00a30d2 | 2021-05-04 13:31:52 -0500 | [diff] [blame] | 3315 | // 1 2 3 4 |
| 3316 | // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 |
| 3317 | // 0008140a00070001 - Download section, AR=0 |
| 3318 | // cc - Section 0xcc |
| 3319 | // 01020304050607080910111213141516171819202122232425262728293031 |
| 3320 | // 00000028 |
| 3321 | func TestExtendedDownloadSectionRequestDecodeNoResponseExpected(t *testing.T) { |
| 3322 | goodMessage := "0008140b00070001" |
| 3323 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 3324 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 3325 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 3326 | sectionNumber := 0x88 |
| 3327 | length := 1 + (8 * 25) |
| 3328 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 3329 | goodMessage += hdr + payloadTotal |
| 3330 | data, err := stringToPacket(goodMessage) |
| 3331 | assert.NoError(t, err) |
| 3332 | |
| 3333 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3334 | assert.NotNil(t, packet) |
| 3335 | assert.Nil(t, packet.ErrorLayer()) |
| 3336 | |
| 3337 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3338 | assert.NotNil(t, omciLayer) |
| 3339 | |
| 3340 | omciMsg, ok := omciLayer.(*OMCI) |
| 3341 | assert.True(t, ok) |
| 3342 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 3343 | assert.Equal(t, DownloadSectionRequestType, omciMsg.MessageType) |
| 3344 | assert.False(t, omciMsg.ResponseExpected) |
| 3345 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 3346 | assert.Equal(t, uint16(length), omciMsg.Length) |
| 3347 | |
| 3348 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 3349 | assert.NotNil(t, msgLayer) |
| 3350 | |
| 3351 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 3352 | assert.True(t, ok2) |
| 3353 | assert.NotNil(t, request) |
| 3354 | assert.Equal(t, uint8(sectionNumber), request.SectionNumber) |
| 3355 | assert.Equal(t, length-1, len(request.SectionData)) |
| 3356 | |
| 3357 | data, err = stringToPacket(payloadTotal) |
| 3358 | assert.NoError(t, err) |
| 3359 | assert.Equal(t, data, request.SectionData[:]) |
| 3360 | |
| 3361 | // Verify string output for message |
| 3362 | packetString := packet.String() |
| 3363 | assert.NotZero(t, len(packetString)) |
| 3364 | } |
| 3365 | |
| 3366 | func TestExtendedDownloadSectionRequestDecodeResponseExpected(t *testing.T) { |
| 3367 | goodMessage := "0008540b00070001" |
| 3368 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 3369 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 3370 | payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 3371 | payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 3372 | payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 3373 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 3374 | sectionNumber := 0x88 |
| 3375 | length := 1 + (20 * 25) |
| 3376 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 3377 | goodMessage += hdr + payloadTotal |
| 3378 | data, err := stringToPacket(goodMessage) |
| 3379 | assert.NoError(t, err) |
| 3380 | |
| 3381 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3382 | assert.NotNil(t, packet) |
| 3383 | assert.Nil(t, packet.ErrorLayer()) |
| 3384 | |
| 3385 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3386 | assert.NotNil(t, omciLayer) |
| 3387 | |
| 3388 | omciMsg, ok := omciLayer.(*OMCI) |
| 3389 | assert.True(t, ok) |
| 3390 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 3391 | assert.Equal(t, DownloadSectionRequestWithResponseType, omciMsg.MessageType) |
| 3392 | assert.True(t, omciMsg.ResponseExpected) |
| 3393 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 3394 | assert.Equal(t, uint16(length), omciMsg.Length) |
| 3395 | |
| 3396 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 3397 | assert.NotNil(t, msgLayer) |
| 3398 | |
| 3399 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 3400 | assert.True(t, ok2) |
| 3401 | assert.NotNil(t, request) |
| 3402 | assert.Equal(t, uint8(sectionNumber), request.SectionNumber) |
| 3403 | assert.Equal(t, length-1, len(request.SectionData)) |
| 3404 | |
| 3405 | data, err = stringToPacket(payloadTotal) |
| 3406 | assert.NoError(t, err) |
| 3407 | assert.Equal(t, data, request.SectionData) |
| 3408 | |
| 3409 | // Verify string output for message |
| 3410 | packetString := packet.String() |
| 3411 | assert.NotZero(t, len(packetString)) |
| 3412 | } |
| 3413 | |
| 3414 | func TestExtendedDownloadSectionRequestDecodeTruncated(t *testing.T) { |
| 3415 | goodMessage := "0008540b000700010000" |
| 3416 | data, err := stringToPacket(goodMessage) |
| 3417 | assert.NoError(t, err) |
| 3418 | |
| 3419 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3420 | assert.NotNil(t, packet) |
| 3421 | |
| 3422 | failure := packet.ErrorLayer() |
| 3423 | assert.NotNil(t, failure) |
| 3424 | |
| 3425 | decodeFailure, ok := failure.(*gopacket.DecodeFailure) |
| 3426 | assert.NotNil(t, decodeFailure) |
| 3427 | assert.True(t, ok) |
| 3428 | assert.NotNil(t, decodeFailure.String()) |
| 3429 | assert.True(t, len(decodeFailure.String()) > 0) |
| 3430 | |
| 3431 | metadata := packet.Metadata() |
| 3432 | assert.NotNil(t, metadata) |
| 3433 | assert.True(t, metadata.Truncated) |
| 3434 | |
| 3435 | // Verify string output for message |
| 3436 | packetString := packet.String() |
| 3437 | assert.NotZero(t, len(packetString)) |
| 3438 | } |
| 3439 | |
| 3440 | func TestExtendedDownloadSectionRequestSerializeNoResponseExpected(t *testing.T) { |
| 3441 | goodMessage := "0123140b00070001" |
| 3442 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 3443 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 3444 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 3445 | sectionNumber := 0x84 |
| 3446 | length := 1 + (8 * 25) |
| 3447 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 3448 | goodMessage += hdr + payloadTotal |
| 3449 | |
| 3450 | omciLayer := &OMCI{ |
| 3451 | TransactionID: 0x0123, |
| 3452 | MessageType: DownloadSectionRequestType, |
| 3453 | DeviceIdentifier: ExtendedIdent, |
| 3454 | } |
| 3455 | sectionData, genErr := stringToPacket(payloadTotal) |
| 3456 | assert.Nil(t, genErr) |
| 3457 | assert.NotNil(t, sectionData) |
| 3458 | assert.Equal(t, len(payloadTotal)/2, len(sectionData)) |
| 3459 | |
| 3460 | request := &DownloadSectionRequest{ |
| 3461 | MeBasePacket: MeBasePacket{ |
| 3462 | EntityClass: me.SoftwareImageClassID, |
| 3463 | EntityInstance: uint16(1), |
| 3464 | Extended: true, |
| 3465 | }, |
| 3466 | SectionNumber: byte(sectionNumber), |
| 3467 | SectionData: sectionData, |
| 3468 | } |
| 3469 | // Test serialization back to former string |
| 3470 | var options gopacket.SerializeOptions |
| 3471 | options.FixLengths = true |
| 3472 | |
| 3473 | buffer := gopacket.NewSerializeBuffer() |
| 3474 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3475 | assert.NoError(t, err) |
| 3476 | |
| 3477 | outgoingPacket := buffer.Bytes() |
| 3478 | reconstituted := packetToString(outgoingPacket) |
| 3479 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3480 | } |
| 3481 | |
| 3482 | func TestExtendedDownloadSectionRequestSerializeResponseExpectedMethod1(t *testing.T) { |
| 3483 | goodMessage := "2468540b00070001" |
| 3484 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 3485 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 3486 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 3487 | sectionNumber := 0x84 |
| 3488 | length := 1 + (8 * 25) |
| 3489 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 3490 | goodMessage += hdr + payloadTotal |
| 3491 | |
| 3492 | omciLayer := &OMCI{ |
| 3493 | TransactionID: 0x2468, |
| 3494 | MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType |
| 3495 | ResponseExpected: true, |
| 3496 | DeviceIdentifier: ExtendedIdent, |
| 3497 | } |
| 3498 | sectionData, genErr := stringToPacket(payloadTotal) |
| 3499 | assert.Nil(t, genErr) |
| 3500 | assert.NotNil(t, sectionData) |
| 3501 | assert.Equal(t, len(payloadTotal)/2, len(sectionData)) |
| 3502 | |
| 3503 | request := &DownloadSectionRequest{ |
| 3504 | MeBasePacket: MeBasePacket{ |
| 3505 | EntityClass: me.SoftwareImageClassID, |
| 3506 | EntityInstance: uint16(1), |
| 3507 | Extended: true, |
| 3508 | }, |
| 3509 | SectionNumber: byte(sectionNumber), |
| 3510 | SectionData: sectionData, |
| 3511 | } |
| 3512 | // Test serialization back to former string |
| 3513 | var options gopacket.SerializeOptions |
| 3514 | options.FixLengths = true |
| 3515 | |
| 3516 | buffer := gopacket.NewSerializeBuffer() |
| 3517 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3518 | assert.NoError(t, err) |
| 3519 | |
| 3520 | outgoingPacket := buffer.Bytes() |
| 3521 | reconstituted := packetToString(outgoingPacket) |
| 3522 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3523 | } |
| 3524 | |
| 3525 | func TestExtendedDownloadSectionRequestSerializeResponseExpectedMethod2(t *testing.T) { |
| 3526 | goodMessage := "2468540b00070001" |
| 3527 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 3528 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 3529 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 3530 | sectionNumber := 0x84 |
| 3531 | length := 1 + (8 * 25) |
| 3532 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 3533 | goodMessage += hdr + payloadTotal |
| 3534 | |
| 3535 | // In this case, just use the request type with AR response requested already encoded |
| 3536 | omciLayer := &OMCI{ |
| 3537 | TransactionID: 0x2468, |
| 3538 | MessageType: DownloadSectionRequestWithResponseType, |
| 3539 | ResponseExpected: true, |
| 3540 | DeviceIdentifier: ExtendedIdent, |
| 3541 | } |
| 3542 | sectionData, genErr := stringToPacket(payloadTotal) |
| 3543 | assert.Nil(t, genErr) |
| 3544 | assert.NotNil(t, sectionData) |
| 3545 | assert.Equal(t, len(payloadTotal)/2, len(sectionData)) |
| 3546 | |
| 3547 | request := &DownloadSectionRequest{ |
| 3548 | MeBasePacket: MeBasePacket{ |
| 3549 | EntityClass: me.SoftwareImageClassID, |
| 3550 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
| 3551 | Extended: true, |
| 3552 | }, |
| 3553 | SectionNumber: byte(sectionNumber), |
| 3554 | SectionData: sectionData, |
| 3555 | } |
| 3556 | // Test serialization back to former string |
| 3557 | var options gopacket.SerializeOptions |
| 3558 | options.FixLengths = true |
| 3559 | |
| 3560 | buffer := gopacket.NewSerializeBuffer() |
| 3561 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3562 | assert.NoError(t, err) |
| 3563 | |
| 3564 | outgoingPacket := buffer.Bytes() |
| 3565 | reconstituted := packetToString(outgoingPacket) |
| 3566 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3567 | } |
| 3568 | |
| 3569 | func TestExtendedDownloadSectionResponseDecode(t *testing.T) { |
| 3570 | goodMessage := "0022340b000700010002061f" |
| 3571 | data, err := stringToPacket(goodMessage) |
| 3572 | assert.NoError(t, err) |
| 3573 | |
| 3574 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3575 | assert.NotNil(t, packet) |
| 3576 | |
| 3577 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3578 | assert.NotNil(t, omciLayer) |
| 3579 | |
| 3580 | omciMsg, ok := omciLayer.(*OMCI) |
| 3581 | assert.True(t, ok) |
| 3582 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0022)) |
| 3583 | assert.Equal(t, omciMsg.MessageType, DownloadSectionResponseType) |
| 3584 | assert.Equal(t, omciMsg.DeviceIdentifier, ExtendedIdent) |
| 3585 | assert.Equal(t, uint16(2), omciMsg.Length) |
| 3586 | |
| 3587 | msgLayer := packet.Layer(LayerTypeDownloadSectionResponse) |
| 3588 | assert.NotNil(t, msgLayer) |
| 3589 | |
| 3590 | response, ok2 := msgLayer.(*DownloadSectionResponse) |
| 3591 | assert.True(t, ok2) |
| 3592 | assert.NotNil(t, response) |
| 3593 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 3594 | assert.Equal(t, byte(0x1f), response.SectionNumber) |
| 3595 | |
| 3596 | // Verify string output for message |
| 3597 | packetString := packet.String() |
| 3598 | assert.NotZero(t, len(packetString)) |
| 3599 | } |
| 3600 | |
| 3601 | func TestExtendedDownloadSectionResponseDecodeTruncated(t *testing.T) { |
| 3602 | goodMessage := "0022340b00070001000106" |
| 3603 | data, err := stringToPacket(goodMessage) |
| 3604 | assert.NoError(t, err) |
| 3605 | |
| 3606 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3607 | assert.NotNil(t, packet) |
| 3608 | |
| 3609 | failure := packet.ErrorLayer() |
| 3610 | assert.NotNil(t, failure) |
| 3611 | |
| 3612 | decodeFailure, ok := failure.(*gopacket.DecodeFailure) |
| 3613 | assert.NotNil(t, decodeFailure) |
| 3614 | assert.True(t, ok) |
| 3615 | assert.NotNil(t, decodeFailure.String()) |
| 3616 | assert.True(t, len(decodeFailure.String()) > 0) |
| 3617 | |
| 3618 | metadata := packet.Metadata() |
| 3619 | assert.NotNil(t, metadata) |
| 3620 | assert.True(t, metadata.Truncated) |
| 3621 | |
| 3622 | // Verify string output for message |
| 3623 | packetString := packet.String() |
| 3624 | assert.NotZero(t, len(packetString)) |
| 3625 | } |
| 3626 | |
| 3627 | func TestExtendedDownloadSectionResponseSerialize(t *testing.T) { |
| 3628 | goodMessage := "0022340b000700010002061f" |
| 3629 | |
| 3630 | omciLayer := &OMCI{ |
| 3631 | TransactionID: 0x0022, |
| 3632 | MessageType: DownloadSectionResponseType, |
| 3633 | DeviceIdentifier: ExtendedIdent, |
| 3634 | } |
| 3635 | request := &DownloadSectionResponse{ |
| 3636 | MeBasePacket: MeBasePacket{ |
| 3637 | EntityClass: me.SoftwareImageClassID, |
| 3638 | EntityInstance: 1, |
| 3639 | Extended: true, |
| 3640 | }, |
| 3641 | Result: me.DeviceBusy, |
| 3642 | SectionNumber: 0x1f, |
| 3643 | } |
| 3644 | // Test serialization back to former string |
| 3645 | var options gopacket.SerializeOptions |
| 3646 | options.FixLengths = true |
| 3647 | |
| 3648 | buffer := gopacket.NewSerializeBuffer() |
| 3649 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3650 | assert.NoError(t, err) |
| 3651 | |
| 3652 | outgoingPacket := buffer.Bytes() |
| 3653 | reconstituted := packetToString(outgoingPacket) |
| 3654 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3655 | } |
| 3656 | |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 3657 | func TestGenericTestResultDecode(t *testing.T) { |
| 3658 | // ONU-G ME for this test with just made up data |
| 3659 | payload := "1234567890123456789012345678901234567890123456789012345678901234" |
| 3660 | goodMessage := "00001b0a01000000" + payload + "00000028" |
| 3661 | data, err := stringToPacket(goodMessage) |
| 3662 | assert.NoError(t, err) |
| 3663 | |
| 3664 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3665 | assert.NotNil(t, packet) |
| 3666 | |
| 3667 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3668 | assert.NotNil(t, omciLayer) |
| 3669 | |
| 3670 | omciMsg, ok := omciLayer.(*OMCI) |
| 3671 | assert.True(t, ok) |
| 3672 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0000)) |
| 3673 | assert.Equal(t, omciMsg.MessageType, TestResultType) |
| 3674 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 3675 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 3676 | |
| 3677 | msgLayer := packet.Layer(LayerTypeTestResult) |
| 3678 | assert.NotNil(t, msgLayer) |
| 3679 | |
| 3680 | // This is a generic struct since we do not do detailed decode |
| 3681 | generic, ok2 := msgLayer.(*TestResultNotification) |
| 3682 | assert.True(t, ok2) |
| 3683 | assert.NotNil(t, generic) |
| 3684 | assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data |
| 3685 | assert.NotNil(t, generic.Payload) |
| 3686 | assert.NotNil(t, generic.TestResults()) |
| 3687 | |
| 3688 | base := generic.MeBasePacket |
| 3689 | assert.Equal(t, me.OnuGClassID, base.EntityClass) |
| 3690 | assert.Equal(t, uint16(0), base.EntityInstance) |
| 3691 | |
| 3692 | // For the generic Test Result, get the payload data which is all the data in |
| 3693 | // the test notification past the Entity Instance value. |
| 3694 | payloadData, payloadErr := stringToPacket(payload) |
| 3695 | assert.NotNil(t, payloadData) |
| 3696 | assert.NoError(t, payloadErr) |
| 3697 | assert.Equal(t, payloadData, base.Payload) |
| 3698 | assert.Equal(t, payloadData, generic.Payload) |
| 3699 | |
| 3700 | // Verify string output for message |
| 3701 | packetString := packet.String() |
| 3702 | assert.NotZero(t, len(packetString)) |
| 3703 | } |
| 3704 | |
| 3705 | func TestOpticalLineSupervisionTestResultDecode(t *testing.T) { |
| 3706 | // ANI-G ME for this test with just made up data |
| 3707 | payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901" + "000000000000000000000000000000" |
| 3708 | goodMessage := "00001b0a01078001" + payload + "00000028" |
| 3709 | data, err := stringToPacket(goodMessage) |
| 3710 | assert.NoError(t, err) |
| 3711 | |
| 3712 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3713 | assert.NotNil(t, packet) |
| 3714 | |
| 3715 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3716 | assert.NotNil(t, omciLayer) |
| 3717 | |
| 3718 | omciMsg, ok := omciLayer.(*OMCI) |
| 3719 | assert.True(t, ok) |
| 3720 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0000)) |
| 3721 | assert.Equal(t, omciMsg.MessageType, TestResultType) |
| 3722 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 3723 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 3724 | |
| 3725 | msgLayer := packet.Layer(LayerTypeTestResult) |
| 3726 | assert.NotNil(t, msgLayer) |
| 3727 | |
| 3728 | // This is a optical line test results |
| 3729 | optical, ok2 := msgLayer.(*OpticalLineSupervisionTestResult) |
| 3730 | assert.True(t, ok2) |
| 3731 | assert.NotNil(t, optical) |
| 3732 | |
| 3733 | // Get the Managed Entity class ID and instance ID from the base packet |
| 3734 | base := optical.MeBasePacket |
| 3735 | assert.Equal(t, me.AniGClassID, base.EntityClass) |
| 3736 | assert.Equal(t, uint16(0x8001), base.EntityInstance) |
| 3737 | |
| 3738 | assert.Equal(t, uint8(1), optical.PowerFeedVoltageType) |
| 3739 | assert.Equal(t, uint16(0x34), optical.PowerFeedVoltage) |
| 3740 | |
| 3741 | assert.Equal(t, uint8(3), optical.ReceivedOpticalPowerType) |
| 3742 | assert.Equal(t, uint16(0x67), optical.ReceivedOpticalPower) |
| 3743 | |
| 3744 | assert.Equal(t, uint8(5), optical.MeanOpticalLaunchType) |
| 3745 | assert.Equal(t, uint16(0x91), optical.MeanOpticalLaunch) |
| 3746 | |
| 3747 | assert.Equal(t, uint8(9), optical.LaserBiasCurrentType) |
| 3748 | assert.Equal(t, uint16(0x34), optical.LaserBiasCurrent) |
| 3749 | |
| 3750 | assert.Equal(t, uint8(12), optical.TemperatureType) |
| 3751 | assert.Equal(t, uint16(0x67), optical.Temperature) |
| 3752 | |
| 3753 | assert.Equal(t, uint16(0x8901), optical.GeneralPurposeBuffer) |
| 3754 | |
| 3755 | // Verify string output for message |
| 3756 | packetString := packet.String() |
| 3757 | assert.NotZero(t, len(packetString)) |
| 3758 | } |
| 3759 | |
| 3760 | func TestGenericTestResultSerialize(t *testing.T) { |
| 3761 | payload := "1234567891234567890123456789012345678901234567890123456789012345" |
| 3762 | goodMessage := "00001b0a01000000" + payload + "00000028" |
| 3763 | |
| 3764 | omciLayer := &OMCI{ |
| 3765 | // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000 |
| 3766 | MessageType: TestResultType, |
| 3767 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 3768 | // Length: 0x28, // Optional, defaults to 40 octets |
| 3769 | } |
| 3770 | data, derr := stringToPacket(payload) |
| 3771 | assert.NoError(t, derr) |
| 3772 | |
| 3773 | request := &TestResultNotification{ |
| 3774 | MeBasePacket: MeBasePacket{ |
| 3775 | EntityClass: me.OnuGClassID, |
| 3776 | EntityInstance: uint16(0), |
| 3777 | }, |
| 3778 | Payload: data, |
| 3779 | } |
| 3780 | // Test serialization back to former string |
| 3781 | var options gopacket.SerializeOptions |
| 3782 | options.FixLengths = true |
| 3783 | |
| 3784 | buffer := gopacket.NewSerializeBuffer() |
| 3785 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3786 | assert.NoError(t, err) |
| 3787 | |
| 3788 | outgoingPacket := buffer.Bytes() |
| 3789 | reconstituted := packetToString(outgoingPacket) |
| 3790 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3791 | } |
| 3792 | |
| 3793 | func TestOpticalLineSupervisionTestResultSerialize(t *testing.T) { |
| 3794 | // ANI-G ME for this test with just made up data |
| 3795 | payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901" + "000000000000000000000000000000" |
| 3796 | goodMessage := "00001b0a01078001" + payload + "00000028" |
| 3797 | |
| 3798 | omciLayer := &OMCI{ |
| 3799 | // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000 |
| 3800 | MessageType: TestResultType, |
| 3801 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 3802 | // Length: 0x28, // Optional, defaults to 40 octets |
| 3803 | } |
| 3804 | request := &OpticalLineSupervisionTestResult{ |
| 3805 | MeBasePacket: MeBasePacket{ |
| 3806 | EntityClass: me.AniGClassID, |
| 3807 | EntityInstance: uint16(0x8001), |
| 3808 | }, |
| 3809 | PowerFeedVoltageType: uint8(1), |
| 3810 | PowerFeedVoltage: uint16(0x34), |
| 3811 | ReceivedOpticalPowerType: uint8(3), |
| 3812 | ReceivedOpticalPower: uint16(0x67), |
| 3813 | MeanOpticalLaunchType: uint8(5), |
| 3814 | MeanOpticalLaunch: uint16(0x91), |
| 3815 | LaserBiasCurrentType: uint8(9), |
| 3816 | LaserBiasCurrent: uint16(0x34), |
| 3817 | TemperatureType: uint8(12), |
| 3818 | Temperature: uint16(0x67), |
| 3819 | GeneralPurposeBuffer: uint16(0x8901), |
| 3820 | } |
| 3821 | // Test serialization back to former string |
| 3822 | var options gopacket.SerializeOptions |
| 3823 | options.FixLengths = true |
| 3824 | |
| 3825 | buffer := gopacket.NewSerializeBuffer() |
| 3826 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3827 | assert.NoError(t, err) |
| 3828 | |
| 3829 | outgoingPacket := buffer.Bytes() |
| 3830 | reconstituted := packetToString(outgoingPacket) |
| 3831 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3832 | } |
| 3833 | |
| 3834 | func TestGenericTestRequestDecode(t *testing.T) { |
| 3835 | // ONU-G ME for this test with just made up data |
| 3836 | payload := "1234567890523456789012345678901234567890123456789012345678901234" |
| 3837 | goodMessage := "0123520a01000000" + payload + "00000028" |
| 3838 | data, err := stringToPacket(goodMessage) |
| 3839 | assert.NoError(t, err) |
| 3840 | |
| 3841 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3842 | assert.NotNil(t, packet) |
| 3843 | |
| 3844 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3845 | assert.NotNil(t, omciLayer) |
| 3846 | |
| 3847 | omciMsg, ok := omciLayer.(*OMCI) |
| 3848 | assert.True(t, ok) |
| 3849 | assert.Equal(t, uint16(0x0123), omciMsg.TransactionID) |
| 3850 | assert.Equal(t, TestRequestType, omciMsg.MessageType) |
| 3851 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 3852 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 3853 | |
Chip Boling | ed6b911 | 2021-05-11 09:14:54 -0500 | [diff] [blame] | 3854 | msgLayer := packet.Layer(LayerTypeTestRequest) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 3855 | assert.NotNil(t, msgLayer) |
| 3856 | |
| 3857 | // This is a generic struct since we do not do detailed decode |
| 3858 | generic, ok2 := msgLayer.(*TestRequest) |
| 3859 | assert.True(t, ok2) |
| 3860 | assert.NotNil(t, generic) |
| 3861 | assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data |
| 3862 | assert.NotNil(t, generic.Payload) |
| 3863 | assert.NotNil(t, generic.TestRequest()) |
| 3864 | |
| 3865 | base := generic.MeBasePacket |
| 3866 | assert.Equal(t, me.OnuGClassID, base.EntityClass) |
| 3867 | assert.Equal(t, uint16(0), base.EntityInstance) |
| 3868 | |
| 3869 | // For the generic Test Result, get the payload data which is all the data in |
| 3870 | // the test notification past the Entity Instance value. |
| 3871 | payloadData, payloadErr := stringToPacket(payload) |
| 3872 | assert.NotNil(t, payloadData) |
| 3873 | assert.NoError(t, payloadErr) |
| 3874 | assert.Equal(t, payloadData, base.Payload) |
| 3875 | assert.Equal(t, payloadData, generic.Payload) |
| 3876 | |
| 3877 | // Verify string output for message |
| 3878 | packetString := packet.String() |
| 3879 | assert.NotZero(t, len(packetString)) |
| 3880 | } |
| 3881 | |
| 3882 | func TestOpticalLineSupervisionTestRequestDecode(t *testing.T) { |
| 3883 | // ANI-G ME for this test with just made up data |
| 3884 | payload := "01" + "1234" + "5678" + "000000000000000000000000000000000000000000000000000000" |
| 3885 | goodMessage := "0ddd520a01078001" + payload + "00000028" |
| 3886 | data, err := stringToPacket(goodMessage) |
| 3887 | assert.NoError(t, err) |
| 3888 | |
| 3889 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3890 | assert.NotNil(t, packet) |
| 3891 | |
| 3892 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3893 | assert.NotNil(t, omciLayer) |
| 3894 | |
| 3895 | omciMsg, ok := omciLayer.(*OMCI) |
| 3896 | assert.True(t, ok) |
| 3897 | assert.Equal(t, uint16(0x0ddd), omciMsg.TransactionID) |
| 3898 | assert.Equal(t, TestRequestType, omciMsg.MessageType) |
| 3899 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 3900 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 3901 | |
Chip Boling | ed6b911 | 2021-05-11 09:14:54 -0500 | [diff] [blame] | 3902 | msgLayer := packet.Layer(LayerTypeTestRequest) |
Chip Boling | d8637b0 | 2021-04-29 08:36:38 -0500 | [diff] [blame] | 3903 | assert.NotNil(t, msgLayer) |
| 3904 | |
| 3905 | // This is a optical line test results |
| 3906 | optical, ok2 := msgLayer.(*OpticalLineSupervisionTestRequest) |
| 3907 | assert.True(t, ok2) |
| 3908 | assert.NotNil(t, optical) |
| 3909 | |
| 3910 | // Get the Managed Entity class ID and instance ID from the base packet |
| 3911 | base := optical.MeBasePacket |
| 3912 | assert.Equal(t, me.AniGClassID, base.EntityClass) |
| 3913 | assert.Equal(t, uint16(0x8001), base.EntityInstance) |
| 3914 | |
| 3915 | assert.Equal(t, uint8(1), optical.SelectTest) |
| 3916 | assert.Equal(t, uint16(0x1234), optical.GeneralPurposeBuffer) |
| 3917 | assert.Equal(t, uint16(0x5678), optical.VendorSpecificParameters) |
| 3918 | |
| 3919 | // Verify string output for message |
| 3920 | packetString := packet.String() |
| 3921 | assert.NotZero(t, len(packetString)) |
| 3922 | } |
| 3923 | |
| 3924 | func TestGenericTestRequestSerialize(t *testing.T) { |
| 3925 | payload := "1234567891234567890123456789012345678901234567890123456789012345" |
| 3926 | goodMessage := "eeee520a01000000" + payload + "00000028" |
| 3927 | |
| 3928 | omciLayer := &OMCI{ |
| 3929 | TransactionID: 0xeeee, |
| 3930 | MessageType: TestRequestType, |
| 3931 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 3932 | // Length: 0x28, // Optional, defaults to 40 octets |
| 3933 | } |
| 3934 | data, derr := stringToPacket(payload) |
| 3935 | assert.NoError(t, derr) |
| 3936 | |
| 3937 | request := &TestRequest{ |
| 3938 | MeBasePacket: MeBasePacket{ |
| 3939 | EntityClass: me.OnuGClassID, |
| 3940 | EntityInstance: uint16(0), |
| 3941 | }, |
| 3942 | Payload: data, |
| 3943 | } |
| 3944 | // Test serialization back to former string |
| 3945 | var options gopacket.SerializeOptions |
| 3946 | options.FixLengths = true |
| 3947 | |
| 3948 | buffer := gopacket.NewSerializeBuffer() |
| 3949 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3950 | assert.NoError(t, err) |
| 3951 | |
| 3952 | outgoingPacket := buffer.Bytes() |
| 3953 | reconstituted := packetToString(outgoingPacket) |
| 3954 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3955 | } |
| 3956 | |
| 3957 | func TestOpticalLineSupervisionTestRequestSerialize(t *testing.T) { |
| 3958 | // ANI-G ME for this test with just made up data |
| 3959 | payload := "01" + "1234" + "5678" + "000000000000000000000000000000000000000000000000000000" |
| 3960 | goodMessage := "bbbb520a01078001" + payload + "00000028" |
| 3961 | |
| 3962 | omciLayer := &OMCI{ |
| 3963 | TransactionID: 0xbbbb, |
| 3964 | MessageType: TestRequestType, |
| 3965 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 3966 | // Length: 0x28, // Optional, defaults to 40 octets |
| 3967 | } |
| 3968 | request := &OpticalLineSupervisionTestRequest{ |
| 3969 | MeBasePacket: MeBasePacket{ |
| 3970 | EntityClass: me.AniGClassID, |
| 3971 | EntityInstance: uint16(0x8001), |
| 3972 | }, |
| 3973 | SelectTest: uint8(1), |
| 3974 | GeneralPurposeBuffer: uint16(0x1234), |
| 3975 | VendorSpecificParameters: uint16(0x5678), |
| 3976 | } |
| 3977 | // Test serialization back to former string |
| 3978 | var options gopacket.SerializeOptions |
| 3979 | options.FixLengths = true |
| 3980 | |
| 3981 | buffer := gopacket.NewSerializeBuffer() |
| 3982 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 3983 | assert.NoError(t, err) |
| 3984 | |
| 3985 | outgoingPacket := buffer.Bytes() |
| 3986 | reconstituted := packetToString(outgoingPacket) |
| 3987 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 3988 | } |
| 3989 | |
| 3990 | func TestTestResponseDecode(t *testing.T) { |
| 3991 | goodMessage := "0001320A01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 3992 | data, err := stringToPacket(goodMessage) |
| 3993 | assert.NoError(t, err) |
| 3994 | |
| 3995 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 3996 | assert.NotNil(t, packet) |
| 3997 | |
| 3998 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 3999 | assert.NotNil(t, omciLayer) |
| 4000 | |
| 4001 | omciMsg, ok := omciLayer.(*OMCI) |
| 4002 | assert.True(t, ok) |
| 4003 | assert.Equal(t, TestResponseType, omciMsg.MessageType) |
| 4004 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 4005 | |
| 4006 | msgLayer := packet.Layer(LayerTypeTestResponse) |
| 4007 | |
| 4008 | assert.NotNil(t, msgLayer) |
| 4009 | |
| 4010 | response, ok2 := msgLayer.(*TestResponse) |
| 4011 | assert.True(t, ok2) |
| 4012 | assert.NotNil(t, response) |
| 4013 | assert.Equal(t, me.OnuGClassID, response.EntityClass) |
| 4014 | assert.Equal(t, uint16(0), response.EntityInstance) |
| 4015 | assert.Equal(t, me.Success, response.Result) |
| 4016 | |
| 4017 | // Verify string output for message |
| 4018 | packetString := packet.String() |
| 4019 | assert.NotZero(t, len(packetString)) |
| 4020 | } |
| 4021 | |
| 4022 | func TestTestResponseSerialize(t *testing.T) { |
| 4023 | goodMessage := "0001320A01000000000000000000000000000000000000000000000000000000000000000000000000000028" |
| 4024 | |
| 4025 | omciLayer := &OMCI{ |
| 4026 | TransactionID: 0x01, |
| 4027 | MessageType: TestResponseType, |
| 4028 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 4029 | // Length: 0x28, // Optional, defaults to 40 octets |
| 4030 | } |
| 4031 | request := &TestResponse{ |
| 4032 | MeBasePacket: MeBasePacket{ |
| 4033 | EntityClass: me.OnuGClassID, |
| 4034 | // Default Instance ID is 0 |
| 4035 | }, |
| 4036 | Result: me.Success, |
| 4037 | } |
| 4038 | // Test serialization back to former string |
| 4039 | var options gopacket.SerializeOptions |
| 4040 | options.FixLengths = true |
| 4041 | |
| 4042 | buffer := gopacket.NewSerializeBuffer() |
| 4043 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 4044 | assert.NoError(t, err) |
| 4045 | |
| 4046 | outgoingPacket := buffer.Bytes() |
| 4047 | reconstituted := packetToString(outgoingPacket) |
| 4048 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 4049 | } |
| 4050 | |
Chip Boling | c15f61d | 2021-05-13 09:07:17 -0500 | [diff] [blame] | 4051 | func TestExtendedAlarmNotificationDecode(t *testing.T) { |
| 4052 | // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 |
| 4053 | goodMessage := "0000100b000b0104001d8000000000000000000000000000000000000000000000000000000005" |
| 4054 | data, err := stringToPacket(goodMessage) |
| 4055 | assert.NoError(t, err) |
| 4056 | |
| 4057 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 4058 | assert.NotNil(t, packet) |
| 4059 | |
| 4060 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 4061 | assert.NotNil(t, omciLayer) |
| 4062 | |
| 4063 | omciMsg, ok := omciLayer.(*OMCI) |
| 4064 | assert.True(t, ok) |
| 4065 | assert.Equal(t, uint16(0x0), omciMsg.TransactionID) |
| 4066 | assert.Equal(t, AlarmNotificationType, omciMsg.MessageType) |
| 4067 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 4068 | assert.Equal(t, uint16(29), omciMsg.Length) |
| 4069 | |
| 4070 | msgLayer := packet.Layer(LayerTypeAlarmNotification) |
| 4071 | assert.NotNil(t, msgLayer) |
| 4072 | |
| 4073 | request, ok2 := msgLayer.(*AlarmNotificationMsg) |
| 4074 | assert.True(t, ok2) |
| 4075 | assert.NotNil(t, request) |
| 4076 | assert.Equal(t, me.PhysicalPathTerminationPointEthernetUniClassID, request.EntityClass) |
| 4077 | assert.Equal(t, uint16(0x104), request.EntityInstance) |
| 4078 | assert.Equal(t, [28]byte{ |
| 4079 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4080 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4081 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4082 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4083 | }, request.AlarmBitmap) |
| 4084 | assert.Equal(t, byte(5), request.AlarmSequenceNumber) |
| 4085 | |
| 4086 | // Active/Clear tests |
| 4087 | active, err2 := request.IsAlarmActive(0) |
| 4088 | clear, err3 := request.IsAlarmClear(0) |
| 4089 | assert.Nil(t, err2) |
| 4090 | assert.Nil(t, err3) |
| 4091 | assert.True(t, active) |
| 4092 | assert.False(t, clear) |
| 4093 | |
| 4094 | // Active/Clear for undefined alarm bits |
| 4095 | active, err2 = request.IsAlarmActive(1) |
| 4096 | clear, err3 = request.IsAlarmClear(1) |
| 4097 | assert.NotNil(t, err2) |
| 4098 | assert.NotNil(t, err3) |
| 4099 | |
| 4100 | // Verify string output for message |
| 4101 | packetString := packet.String() |
| 4102 | assert.NotZero(t, len(packetString)) |
| 4103 | } |
| 4104 | |
| 4105 | func TestExtendedAlarmNotificationSerialize(t *testing.T) { |
| 4106 | // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 |
| 4107 | goodMessage := "0000100b000b0104001d8000000000000000000000000000000000000000000000000000000005" |
| 4108 | |
| 4109 | omciLayer := &OMCI{ |
| 4110 | TransactionID: 0, |
| 4111 | MessageType: AlarmNotificationType, |
| 4112 | DeviceIdentifier: ExtendedIdent, |
| 4113 | // Length parameter is optional for Extended message format serialization |
| 4114 | // and if present it will be overwritten during the serialization with the |
| 4115 | // actual value. |
| 4116 | } |
| 4117 | request := &AlarmNotificationMsg{ |
| 4118 | MeBasePacket: MeBasePacket{ |
| 4119 | EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 4120 | EntityInstance: uint16(0x104), |
| 4121 | Extended: true, |
| 4122 | }, |
| 4123 | AlarmBitmap: [28]byte{ |
| 4124 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4125 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4126 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4127 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4128 | }, |
| 4129 | AlarmSequenceNumber: byte(5), |
| 4130 | } |
| 4131 | // Test serialization back to former string |
| 4132 | var options gopacket.SerializeOptions |
| 4133 | options.FixLengths = true |
| 4134 | |
| 4135 | buffer := gopacket.NewSerializeBuffer() |
| 4136 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 4137 | assert.NoError(t, err) |
| 4138 | |
| 4139 | outgoingPacket := buffer.Bytes() |
| 4140 | reconstituted := packetToString(outgoingPacket) |
| 4141 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 4142 | } |
| 4143 | |
| 4144 | func TestExtendedAttributeValueChangeDecode(t *testing.T) { |
| 4145 | // Software Image Version (14 bytes) AVC |
| 4146 | goodMessage := "0000110b00070000001080004d4c2d3336323600000000000000" |
| 4147 | data, err := stringToPacket(goodMessage) |
| 4148 | assert.NoError(t, err) |
| 4149 | |
| 4150 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 4151 | assert.NotNil(t, packet) |
| 4152 | |
| 4153 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 4154 | assert.NotNil(t, omciLayer) |
| 4155 | |
| 4156 | omciMsg, ok := omciLayer.(*OMCI) |
| 4157 | assert.True(t, ok) |
| 4158 | assert.Equal(t, uint16(0x0), omciMsg.TransactionID) |
| 4159 | assert.Equal(t, AttributeValueChangeType, omciMsg.MessageType) |
| 4160 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 4161 | assert.Equal(t, uint16(2+14), omciMsg.Length) |
| 4162 | |
| 4163 | msgLayer := packet.Layer(LayerTypeAttributeValueChange) |
| 4164 | assert.NotNil(t, msgLayer) |
| 4165 | |
| 4166 | request, ok2 := msgLayer.(*AttributeValueChangeMsg) |
| 4167 | assert.True(t, ok2) |
| 4168 | assert.NotNil(t, request) |
| 4169 | assert.Equal(t, uint16(0x8000), request.AttributeMask) |
| 4170 | assert.Equal(t, me.SoftwareImageClassID, request.EntityClass) |
| 4171 | assert.Equal(t, uint16(0), request.EntityInstance) |
| 4172 | assert.Equal(t, []byte{ |
| 4173 | 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36, |
| 4174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, request.Attributes["Version"]) |
| 4175 | |
| 4176 | // Verify string output for message |
| 4177 | packetString := packet.String() |
| 4178 | assert.NotZero(t, len(packetString)) |
| 4179 | } |
| 4180 | |
| 4181 | func TestExtendedAttributeValueChangeSerialize(t *testing.T) { |
| 4182 | goodMessage := "0000110b00070000001080004d4c2d3336323600000000000000" |
| 4183 | |
| 4184 | omciLayer := &OMCI{ |
| 4185 | TransactionID: 0, |
| 4186 | MessageType: AttributeValueChangeType, |
| 4187 | DeviceIdentifier: ExtendedIdent, |
| 4188 | // Length parameter is optional for Extended message format serialization |
| 4189 | // and if present it will be overwritten during the serialization with the |
| 4190 | // actual value. |
| 4191 | } |
| 4192 | request := &AttributeValueChangeMsg{ |
| 4193 | MeBasePacket: MeBasePacket{ |
| 4194 | EntityClass: me.SoftwareImageClassID, |
| 4195 | EntityInstance: uint16(0), |
| 4196 | Extended: true, |
| 4197 | }, |
| 4198 | AttributeMask: uint16(0x8000), |
| 4199 | Attributes: me.AttributeValueMap{ |
| 4200 | "Version": []byte{ |
| 4201 | 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36, |
| 4202 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4203 | }, |
| 4204 | }, |
| 4205 | } |
| 4206 | // Test serialization back to former string |
| 4207 | var options gopacket.SerializeOptions |
| 4208 | options.FixLengths = true |
| 4209 | |
| 4210 | buffer := gopacket.NewSerializeBuffer() |
| 4211 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 4212 | assert.NoError(t, err) |
| 4213 | |
| 4214 | outgoingPacket := buffer.Bytes() |
| 4215 | reconstituted := packetToString(outgoingPacket) |
| 4216 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 4217 | } |
| 4218 | |
| 4219 | func TestExtendedGenericTestResultDecode(t *testing.T) { |
| 4220 | // ONU-G ME for this test with just made up data |
| 4221 | payload := "1234567890123456789012345678901234567890" |
| 4222 | resultLen := len(payload) / 2 |
| 4223 | goodMessage := "00001b0b01000000" + fmt.Sprintf("%04x", resultLen) + payload |
| 4224 | data, err := stringToPacket(goodMessage) |
| 4225 | assert.NoError(t, err) |
| 4226 | |
| 4227 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 4228 | assert.NotNil(t, packet) |
| 4229 | |
| 4230 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 4231 | assert.NotNil(t, omciLayer) |
| 4232 | |
| 4233 | omciMsg, ok := omciLayer.(*OMCI) |
| 4234 | assert.True(t, ok) |
| 4235 | assert.Equal(t, uint16(0x0000), omciMsg.TransactionID) |
| 4236 | assert.Equal(t, TestResultType, omciMsg.MessageType) |
| 4237 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 4238 | assert.Equal(t, omciMsg.Length, uint16(resultLen)) |
| 4239 | |
| 4240 | msgLayer := packet.Layer(LayerTypeTestResult) |
| 4241 | assert.NotNil(t, msgLayer) |
| 4242 | |
| 4243 | // This is a generic struct since we do not do detailed decode |
| 4244 | generic, ok2 := msgLayer.(*TestResultNotification) |
| 4245 | assert.True(t, ok2) |
| 4246 | assert.NotNil(t, generic) |
| 4247 | assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data |
| 4248 | assert.NotNil(t, generic.Payload) |
| 4249 | assert.NotNil(t, generic.TestResults()) |
| 4250 | |
| 4251 | base := generic.MeBasePacket |
| 4252 | assert.Equal(t, me.OnuGClassID, base.EntityClass) |
| 4253 | assert.Equal(t, uint16(0), base.EntityInstance) |
| 4254 | |
| 4255 | // For the generic Test Result, get the payload data which is all the data in |
| 4256 | // the test notification past the Entity Instance value. |
| 4257 | payloadData, payloadErr := stringToPacket(payload) |
| 4258 | assert.NotNil(t, payloadData) |
| 4259 | assert.NoError(t, payloadErr) |
| 4260 | assert.Equal(t, payloadData, base.Payload) |
| 4261 | assert.Equal(t, payloadData, generic.Payload) |
| 4262 | |
| 4263 | // Verify string output for message |
| 4264 | packetString := packet.String() |
| 4265 | assert.NotZero(t, len(packetString)) |
| 4266 | } |
| 4267 | |
| 4268 | func TestExtendedOpticalLineSupervisionTestResultDecode(t *testing.T) { |
| 4269 | // ANI-G ME for this test with just made up data |
| 4270 | payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901" |
| 4271 | resultLen := len(payload) / 2 |
| 4272 | goodMessage := "00001b0b01078001" + fmt.Sprintf("%04x", resultLen) + payload |
| 4273 | data, err := stringToPacket(goodMessage) |
| 4274 | assert.NoError(t, err) |
| 4275 | |
| 4276 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 4277 | assert.NotNil(t, packet) |
| 4278 | |
| 4279 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 4280 | assert.NotNil(t, omciLayer) |
| 4281 | |
| 4282 | omciMsg, ok := omciLayer.(*OMCI) |
| 4283 | assert.True(t, ok) |
| 4284 | assert.Equal(t, uint16(0x0000), omciMsg.TransactionID) |
| 4285 | assert.Equal(t, TestResultType, omciMsg.MessageType) |
| 4286 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 4287 | assert.Equal(t, uint16(resultLen), omciMsg.Length) |
| 4288 | |
| 4289 | msgLayer := packet.Layer(LayerTypeTestResult) |
| 4290 | assert.NotNil(t, msgLayer) |
| 4291 | |
| 4292 | // This is a optical line test results |
| 4293 | optical, ok2 := msgLayer.(*OpticalLineSupervisionTestResult) |
| 4294 | assert.True(t, ok2) |
| 4295 | assert.NotNil(t, optical) |
| 4296 | |
| 4297 | // Get the Managed Entity class ID and instance ID from the base packet |
| 4298 | base := optical.MeBasePacket |
| 4299 | assert.Equal(t, me.AniGClassID, base.EntityClass) |
| 4300 | assert.Equal(t, uint16(0x8001), base.EntityInstance) |
| 4301 | |
| 4302 | assert.Equal(t, uint8(1), optical.PowerFeedVoltageType) |
| 4303 | assert.Equal(t, uint16(0x34), optical.PowerFeedVoltage) |
| 4304 | |
| 4305 | assert.Equal(t, uint8(3), optical.ReceivedOpticalPowerType) |
| 4306 | assert.Equal(t, uint16(0x67), optical.ReceivedOpticalPower) |
| 4307 | |
| 4308 | assert.Equal(t, uint8(5), optical.MeanOpticalLaunchType) |
| 4309 | assert.Equal(t, uint16(0x91), optical.MeanOpticalLaunch) |
| 4310 | |
| 4311 | assert.Equal(t, uint8(9), optical.LaserBiasCurrentType) |
| 4312 | assert.Equal(t, uint16(0x34), optical.LaserBiasCurrent) |
| 4313 | |
| 4314 | assert.Equal(t, uint8(12), optical.TemperatureType) |
| 4315 | assert.Equal(t, uint16(0x67), optical.Temperature) |
| 4316 | |
| 4317 | assert.Equal(t, uint16(0x8901), optical.GeneralPurposeBuffer) |
| 4318 | |
| 4319 | // Verify string output for message |
| 4320 | packetString := packet.String() |
| 4321 | assert.NotZero(t, len(packetString)) |
| 4322 | } |
| 4323 | |
| 4324 | func TestExtendedGenericTestResultSerialize(t *testing.T) { |
| 4325 | payload := "12345678901234567890" |
| 4326 | resultLen := len(payload) / 2 |
| 4327 | goodMessage := "00001b0b01000000" + fmt.Sprintf("%04x", resultLen) + payload |
| 4328 | |
| 4329 | omciLayer := &OMCI{ |
| 4330 | // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000 |
| 4331 | MessageType: TestResultType, |
| 4332 | DeviceIdentifier: ExtendedIdent, |
| 4333 | // Length parameter is optional for Extended message format serialization |
| 4334 | // and if present it will be overwritten during the serialization with the |
| 4335 | // actual value. |
| 4336 | } |
| 4337 | data, derr := stringToPacket(payload) |
| 4338 | assert.NoError(t, derr) |
| 4339 | |
| 4340 | request := &TestResultNotification{ |
| 4341 | MeBasePacket: MeBasePacket{ |
| 4342 | EntityClass: me.OnuGClassID, |
| 4343 | EntityInstance: uint16(0), |
| 4344 | Extended: true, |
| 4345 | }, |
| 4346 | Payload: data, |
| 4347 | } |
| 4348 | // Test serialization back to former string |
| 4349 | var options gopacket.SerializeOptions |
| 4350 | options.FixLengths = true |
| 4351 | |
| 4352 | buffer := gopacket.NewSerializeBuffer() |
| 4353 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 4354 | assert.NoError(t, err) |
| 4355 | |
| 4356 | outgoingPacket := buffer.Bytes() |
| 4357 | reconstituted := packetToString(outgoingPacket) |
| 4358 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 4359 | } |
| 4360 | |
| 4361 | func TestExtendedOpticalLineSupervisionTestResultSerialize(t *testing.T) { |
| 4362 | // ANI-G ME for this test with just made up data |
| 4363 | payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901" |
| 4364 | resultLen := len(payload) / 2 |
| 4365 | goodMessage := "00001b0b01078001" + fmt.Sprintf("%04x", resultLen) + payload |
| 4366 | |
| 4367 | omciLayer := &OMCI{ |
| 4368 | // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000 |
| 4369 | MessageType: TestResultType, |
| 4370 | DeviceIdentifier: ExtendedIdent, |
| 4371 | // Length parameter is optional for Extended message format serialization |
| 4372 | // and if present it will be overwritten during the serialization with the |
| 4373 | // actual value. |
| 4374 | } |
| 4375 | request := &OpticalLineSupervisionTestResult{ |
| 4376 | MeBasePacket: MeBasePacket{ |
| 4377 | EntityClass: me.AniGClassID, |
| 4378 | EntityInstance: uint16(0x8001), |
| 4379 | Extended: true, |
| 4380 | }, |
| 4381 | PowerFeedVoltageType: uint8(1), |
| 4382 | PowerFeedVoltage: uint16(0x34), |
| 4383 | ReceivedOpticalPowerType: uint8(3), |
| 4384 | ReceivedOpticalPower: uint16(0x67), |
| 4385 | MeanOpticalLaunchType: uint8(5), |
| 4386 | MeanOpticalLaunch: uint16(0x91), |
| 4387 | LaserBiasCurrentType: uint8(9), |
| 4388 | LaserBiasCurrent: uint16(0x34), |
| 4389 | TemperatureType: uint8(12), |
| 4390 | Temperature: uint16(0x67), |
| 4391 | GeneralPurposeBuffer: uint16(0x8901), |
| 4392 | } |
| 4393 | // Test serialization back to former string |
| 4394 | var options gopacket.SerializeOptions |
| 4395 | options.FixLengths = true |
| 4396 | |
| 4397 | buffer := gopacket.NewSerializeBuffer() |
| 4398 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 4399 | assert.NoError(t, err) |
| 4400 | |
| 4401 | outgoingPacket := buffer.Bytes() |
| 4402 | reconstituted := packetToString(outgoingPacket) |
| 4403 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 4404 | } |
| 4405 | |
Chip Boling | f73bf3e | 2021-06-01 08:43:52 -0500 | [diff] [blame] | 4406 | func TestGetCurrentDataRequestDecode(t *testing.T) { |
Chip Boling | 7a6e8d9 | 2021-07-14 15:42:21 -0500 | [diff] [blame] | 4407 | goodMessage := "035e5c0a01a90000004400000000000000000000000000000000000000000000000000000000000000000028" |
Chip Boling | f73bf3e | 2021-06-01 08:43:52 -0500 | [diff] [blame] | 4408 | data, err := stringToPacket(goodMessage) |
| 4409 | assert.NoError(t, err) |
| 4410 | |
| 4411 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 4412 | assert.NotNil(t, packet) |
| 4413 | |
| 4414 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 4415 | assert.NotNil(t, omciLayer) |
| 4416 | |
| 4417 | omciMsg, ok := omciLayer.(*OMCI) |
| 4418 | assert.True(t, ok) |
| 4419 | assert.Equal(t, uint16(0x035e), omciMsg.TransactionID) |
| 4420 | assert.Equal(t, GetCurrentDataRequestType, omciMsg.MessageType) |
| 4421 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 4422 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 4423 | |
| 4424 | msgLayer := packet.Layer(LayerTypeGetCurrentDataRequest) |
| 4425 | assert.NotNil(t, msgLayer) |
| 4426 | |
| 4427 | request, ok2 := msgLayer.(*GetCurrentDataRequest) |
| 4428 | assert.True(t, ok2) |
| 4429 | assert.NotNil(t, request) |
| 4430 | assert.Equal(t, me.EthernetFrameExtendedPm64BitClassID, request.EntityClass) |
| 4431 | assert.Equal(t, uint16(0), request.EntityInstance) |
| 4432 | assert.Equal(t, uint16(0x0044), request.AttributeMask) |
| 4433 | |
| 4434 | // Verify string output for message |
| 4435 | packetString := packet.String() |
| 4436 | assert.NotZero(t, len(packetString)) |
| 4437 | } |
| 4438 | |
| 4439 | func TestGetCurrentDataRequestSerialize(t *testing.T) { |
Chip Boling | 7a6e8d9 | 2021-07-14 15:42:21 -0500 | [diff] [blame] | 4440 | goodMessage := "035e5c0a01a90000004400000000000000000000000000000000000000000000000000000000000000000028" |
Chip Boling | f73bf3e | 2021-06-01 08:43:52 -0500 | [diff] [blame] | 4441 | |
| 4442 | omciLayer := &OMCI{ |
| 4443 | TransactionID: 0x035e, |
| 4444 | MessageType: GetCurrentDataRequestType, |
| 4445 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 4446 | // Length: 0x28, // Optional, defaults to 40 octets |
| 4447 | } |
| 4448 | request := &GetCurrentDataRequest{ |
| 4449 | MeBasePacket: MeBasePacket{ |
| 4450 | EntityClass: me.EthernetFrameExtendedPm64BitClassID, |
| 4451 | EntityInstance: uint16(0), |
| 4452 | }, |
| 4453 | AttributeMask: uint16(0x0044), |
| 4454 | } |
| 4455 | // Test serialization back to former string |
| 4456 | var options gopacket.SerializeOptions |
| 4457 | options.FixLengths = true |
| 4458 | |
| 4459 | buffer := gopacket.NewSerializeBuffer() |
| 4460 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 4461 | assert.NoError(t, err) |
| 4462 | |
| 4463 | outgoingPacket := buffer.Bytes() |
| 4464 | reconstituted := packetToString(outgoingPacket) |
| 4465 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 4466 | } |
| 4467 | |
| 4468 | func TestGetCurrentDataResponseDecode(t *testing.T) { |
Chip Boling | 7a6e8d9 | 2021-07-14 15:42:21 -0500 | [diff] [blame] | 4469 | goodMessage := "035e3c0a01a90000000044123456781234dbcb432187654321dac1000000000000000000000000000028" |
Chip Boling | f73bf3e | 2021-06-01 08:43:52 -0500 | [diff] [blame] | 4470 | data, err := stringToPacket(goodMessage) |
| 4471 | assert.NoError(t, err) |
| 4472 | |
| 4473 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 4474 | assert.NotNil(t, packet) |
| 4475 | |
| 4476 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 4477 | assert.NotNil(t, omciLayer) |
| 4478 | |
| 4479 | omciMsg, ok := omciLayer.(*OMCI) |
| 4480 | assert.True(t, ok) |
| 4481 | assert.Equal(t, uint16(0x035e), omciMsg.TransactionID) |
| 4482 | assert.Equal(t, GetCurrentDataResponseType, omciMsg.MessageType) |
| 4483 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 4484 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 4485 | |
| 4486 | msgLayer := packet.Layer(LayerTypeGetCurrentDataResponse) |
| 4487 | assert.NotNil(t, msgLayer) |
| 4488 | |
| 4489 | response, ok2 := msgLayer.(*GetCurrentDataResponse) |
| 4490 | assert.True(t, ok2) |
| 4491 | assert.NotNil(t, response) |
| 4492 | assert.Equal(t, me.EthernetFrameExtendedPm64BitClassID, response.EntityClass) |
| 4493 | assert.Equal(t, uint16(0), response.EntityInstance) |
| 4494 | assert.Equal(t, me.Success, response.Result) |
| 4495 | assert.Equal(t, uint16(0x0044), response.AttributeMask) |
| 4496 | assert.Equal(t, uint64(0x123456781234dbcb), response.Attributes["OversizeFrames"]) |
| 4497 | assert.Equal(t, uint64(0x432187654321dac1), response.Attributes["Frames256To511Octets"]) |
| 4498 | |
| 4499 | // Verify string output for message |
| 4500 | packetString := packet.String() |
| 4501 | assert.NotZero(t, len(packetString)) |
| 4502 | } |
| 4503 | |
| 4504 | func TestGetCurrentDataResponseSerialize(t *testing.T) { |
Chip Boling | 7a6e8d9 | 2021-07-14 15:42:21 -0500 | [diff] [blame] | 4505 | goodMessage := "035e3c0a01a90000000044123456781234dbcb432187654321dac10000000000000000000000000000000028" |
Chip Boling | f73bf3e | 2021-06-01 08:43:52 -0500 | [diff] [blame] | 4506 | |
| 4507 | omciLayer := &OMCI{ |
| 4508 | TransactionID: 0x035e, |
| 4509 | MessageType: GetCurrentDataResponseType, |
| 4510 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 4511 | // Length: 0x28, // Optional, defaults to 40 octets |
| 4512 | } |
| 4513 | request := &GetCurrentDataResponse{ |
| 4514 | MeBasePacket: MeBasePacket{ |
| 4515 | EntityClass: me.EthernetFrameExtendedPm64BitClassID, |
| 4516 | EntityInstance: uint16(0), |
| 4517 | }, |
| 4518 | Result: 0, |
| 4519 | AttributeMask: uint16(0x0044), |
| 4520 | Attributes: me.AttributeValueMap{ |
| 4521 | "OversizeFrames": uint64(0x123456781234dbcb), |
| 4522 | "Frames256To511Octets": uint64(0x432187654321dac1), |
| 4523 | // BroadcastFrames can be supplied but will not be encoded since not in attribute mask. |
| 4524 | "BroadcastFrames": uint64(0x0123456789abcdef)}, |
| 4525 | } |
| 4526 | // Test serialization back to former string |
| 4527 | var options gopacket.SerializeOptions |
| 4528 | options.FixLengths = true |
| 4529 | |
| 4530 | buffer := gopacket.NewSerializeBuffer() |
| 4531 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 4532 | assert.NoError(t, err) |
| 4533 | |
| 4534 | outgoingPacket := buffer.Bytes() |
| 4535 | reconstituted := packetToString(outgoingPacket) |
| 4536 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 4537 | } |
| 4538 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 4539 | // TODO: Also remember to add extended message tests to the meframe_test.go |
| 4540 | // unit tests as more message types are supported |