Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
| 3 | * Copyright 2020-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package omci_test |
| 19 | |
| 20 | import ( |
| 21 | "fmt" |
| 22 | "github.com/google/gopacket" |
| 23 | . "github.com/opencord/omci-lib-go" |
| 24 | me "github.com/opencord/omci-lib-go/generated" |
| 25 | "github.com/stretchr/testify/assert" |
| 26 | "strings" |
| 27 | "testing" |
| 28 | ) |
| 29 | |
| 30 | func TestStartSoftwareDownloadRequestDecode(t *testing.T) { |
| 31 | goodMessage := "0004530a00070001ff000f424001000100000000000000000000000000000000000000000000000000000028" |
| 32 | data, err := stringToPacket(goodMessage) |
| 33 | assert.NoError(t, err) |
| 34 | |
| 35 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 36 | assert.NotNil(t, packet) |
| 37 | |
| 38 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 39 | assert.NotNil(t, omciLayer) |
| 40 | |
| 41 | omciMsg, ok := omciLayer.(*OMCI) |
| 42 | assert.True(t, ok) |
| 43 | assert.NotNil(t, omciMsg) |
| 44 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 45 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 46 | assert.Equal(t, LayerTypeStartSoftwareDownloadRequest, omciMsg.NextLayerType()) |
| 47 | assert.Equal(t, uint16(0x0004), omciMsg.TransactionID) |
| 48 | assert.Equal(t, StartSoftwareDownloadRequestType, omciMsg.MessageType) |
| 49 | assert.True(t, omciMsg.ResponseExpected) |
| 50 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 51 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 52 | |
| 53 | msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest) |
| 54 | assert.NotNil(t, msgLayer) |
| 55 | |
| 56 | request, ok2 := msgLayer.(*StartSoftwareDownloadRequest) |
| 57 | assert.True(t, ok2) |
| 58 | assert.NotNil(t, request) |
| 59 | assert.Equal(t, LayerTypeStartSoftwareDownloadRequest, request.LayerType()) |
| 60 | assert.Equal(t, LayerTypeStartSoftwareDownloadRequest, request.CanDecode()) |
| 61 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 62 | assert.Equal(t, uint8(0xff), request.WindowSize) |
| 63 | assert.Equal(t, uint32(0x000f4240), request.ImageSize) |
| 64 | assert.Equal(t, uint8(1), request.NumberOfCircuitPacks) |
| 65 | assert.NotNil(t, request.CircuitPacks) |
| 66 | assert.Equal(t, 1, len(request.CircuitPacks)) |
| 67 | assert.Equal(t, uint16(1), request.CircuitPacks[0]) |
| 68 | |
| 69 | // Verify string output for message |
| 70 | packetString := packet.String() |
| 71 | assert.NotZero(t, len(packetString)) |
| 72 | } |
| 73 | |
| 74 | func TestStartSoftwareDownloadRequestDecodeExtended(t *testing.T) { |
| 75 | goodMessage := "0004530b000700010008ff000f4240010001" |
| 76 | data, err := stringToPacket(goodMessage) |
| 77 | assert.NoError(t, err) |
| 78 | |
| 79 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 80 | assert.NotNil(t, packet) |
| 81 | |
| 82 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 83 | assert.NotNil(t, omciLayer) |
| 84 | |
| 85 | omciMsg, ok := omciLayer.(*OMCI) |
| 86 | assert.True(t, ok) |
| 87 | assert.NotNil(t, omciMsg) |
| 88 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 89 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 90 | assert.Equal(t, LayerTypeStartSoftwareDownloadRequest, omciMsg.NextLayerType()) |
| 91 | assert.Equal(t, uint16(0x0004), omciMsg.TransactionID) |
| 92 | assert.Equal(t, StartSoftwareDownloadRequestType, omciMsg.MessageType) |
| 93 | assert.True(t, omciMsg.ResponseExpected) |
| 94 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 95 | assert.Equal(t, uint16(8), omciMsg.Length) |
| 96 | |
| 97 | msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest) |
| 98 | assert.NotNil(t, msgLayer) |
| 99 | |
| 100 | request, ok2 := msgLayer.(*StartSoftwareDownloadRequest) |
| 101 | assert.True(t, ok2) |
| 102 | assert.NotNil(t, request) |
| 103 | assert.Equal(t, LayerTypeStartSoftwareDownloadRequest, request.LayerType()) |
| 104 | assert.Equal(t, LayerTypeStartSoftwareDownloadRequest, request.CanDecode()) |
| 105 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 106 | assert.Equal(t, uint8(0xff), request.WindowSize) |
| 107 | assert.Equal(t, uint32(0x000f4240), request.ImageSize) |
| 108 | assert.Equal(t, uint8(1), request.NumberOfCircuitPacks) |
| 109 | assert.NotNil(t, request.CircuitPacks) |
| 110 | assert.Equal(t, 1, len(request.CircuitPacks)) |
| 111 | assert.Equal(t, uint16(1), request.CircuitPacks[0]) |
| 112 | |
| 113 | // Verify string output for message |
| 114 | packetString := packet.String() |
| 115 | assert.NotZero(t, len(packetString)) |
| 116 | } |
| 117 | |
| 118 | func TestStartSoftwareDownloadRequestSerialize(t *testing.T) { |
| 119 | goodMessage := "0004530a00070001ff000f424001000100000000000000000000000000000000000000000000000000000028" |
| 120 | |
| 121 | omciLayer := &OMCI{ |
| 122 | TransactionID: 0x04, |
| 123 | MessageType: StartSoftwareDownloadRequestType, |
| 124 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 125 | // Length: 0x28, // Optional, defaults to 40 octets |
| 126 | } |
| 127 | request := &StartSoftwareDownloadRequest{ |
| 128 | MeBasePacket: MeBasePacket{ |
| 129 | EntityClass: me.SoftwareImageClassID, |
| 130 | EntityInstance: 1, |
| 131 | }, |
| 132 | WindowSize: 255, |
| 133 | ImageSize: 0x000f4240, |
| 134 | NumberOfCircuitPacks: 1, |
| 135 | CircuitPacks: []uint16{0x0001}, |
| 136 | } |
| 137 | // Test serialization back to former string |
| 138 | var options gopacket.SerializeOptions |
| 139 | options.FixLengths = true |
| 140 | |
| 141 | buffer := gopacket.NewSerializeBuffer() |
| 142 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 143 | assert.NoError(t, err) |
| 144 | |
| 145 | outgoingPacket := buffer.Bytes() |
| 146 | reconstituted := packetToString(outgoingPacket) |
| 147 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 148 | } |
| 149 | |
| 150 | func TestStartSoftwareDownloadRequestZeroTICSerialize(t *testing.T) { |
| 151 | omciLayer := &OMCI{ |
| 152 | TransactionID: 0x0, |
| 153 | MessageType: StartSoftwareDownloadRequestType, |
| 154 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 155 | // Length: 0x28, // Optional, defaults to 40 octets |
| 156 | } |
| 157 | request := &StartSoftwareDownloadRequest{ |
| 158 | MeBasePacket: MeBasePacket{ |
| 159 | EntityClass: me.SoftwareImageClassID, |
| 160 | EntityInstance: 1, |
| 161 | }, |
| 162 | WindowSize: 255, |
| 163 | ImageSize: 0x000f4240, |
| 164 | NumberOfCircuitPacks: 1, |
| 165 | CircuitPacks: []uint16{0x0001}, |
| 166 | } |
| 167 | // Test serialization back to former string |
| 168 | var options gopacket.SerializeOptions |
| 169 | options.FixLengths = true |
| 170 | |
| 171 | buffer := gopacket.NewSerializeBuffer() |
| 172 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 173 | assert.Error(t, err) |
| 174 | } |
| 175 | |
| 176 | func TestStartSoftwareDownloadRequestSerializeExtended(t *testing.T) { |
| 177 | goodMessage := "0004530b000700010008ff000f4240010001" |
| 178 | |
| 179 | omciLayer := &OMCI{ |
| 180 | TransactionID: 0x04, |
| 181 | MessageType: StartSoftwareDownloadRequestType, |
| 182 | DeviceIdentifier: ExtendedIdent, |
| 183 | } |
| 184 | request := &StartSoftwareDownloadRequest{ |
| 185 | MeBasePacket: MeBasePacket{ |
| 186 | EntityClass: me.SoftwareImageClassID, |
| 187 | EntityInstance: 1, |
| 188 | Extended: true, |
| 189 | }, |
| 190 | WindowSize: 255, |
| 191 | ImageSize: 0x000f4240, |
| 192 | NumberOfCircuitPacks: 1, |
| 193 | CircuitPacks: []uint16{0x0001}, |
| 194 | } |
| 195 | // Test serialization back to former string |
| 196 | var options gopacket.SerializeOptions |
| 197 | options.FixLengths = true |
| 198 | |
| 199 | buffer := gopacket.NewSerializeBuffer() |
| 200 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 201 | assert.NoError(t, err) |
| 202 | |
| 203 | outgoingPacket := buffer.Bytes() |
| 204 | reconstituted := packetToString(outgoingPacket) |
| 205 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 206 | } |
| 207 | |
| 208 | func TestStartSoftwareDownloadResponseDecode(t *testing.T) { |
| 209 | goodMessage := "0004330a0007000100ff00000000000000000000000000000000000000000000000000000000000000000028" |
| 210 | data, err := stringToPacket(goodMessage) |
| 211 | assert.NoError(t, err) |
| 212 | |
| 213 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 214 | assert.NotNil(t, packet) |
| 215 | |
| 216 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 217 | assert.NotNil(t, omciLayer) |
| 218 | |
| 219 | omciMsg, ok := omciLayer.(*OMCI) |
| 220 | assert.True(t, ok) |
| 221 | assert.Equal(t, omciMsg.TransactionID, uint16(0x0004)) |
| 222 | assert.Equal(t, omciMsg.MessageType, StartSoftwareDownloadResponseType) |
| 223 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 224 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 225 | |
| 226 | msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadResponse) |
| 227 | |
| 228 | assert.NotNil(t, msgLayer) |
| 229 | |
| 230 | response, ok2 := msgLayer.(*StartSoftwareDownloadResponse) |
| 231 | assert.True(t, ok2) |
| 232 | assert.NotNil(t, response) |
| 233 | assert.Equal(t, me.Success, response.Result) |
| 234 | assert.Equal(t, uint8(0xff), response.WindowSize) |
| 235 | assert.Equal(t, uint8(0), response.NumberOfInstances) |
| 236 | assert.Nil(t, response.MeResults) |
| 237 | |
| 238 | // Verify string output for message |
| 239 | packetString := packet.String() |
| 240 | assert.NotZero(t, len(packetString)) |
| 241 | } |
| 242 | |
| 243 | func TestStartSoftwareDownloadResponseDecodeExtended(t *testing.T) { |
| 244 | goodMessage := "0004330b00070001000300ff00" |
| 245 | data, err := stringToPacket(goodMessage) |
| 246 | assert.NoError(t, err) |
| 247 | |
| 248 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 249 | assert.NotNil(t, packet) |
| 250 | |
| 251 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 252 | assert.NotNil(t, omciLayer) |
| 253 | |
| 254 | omciMsg, ok := omciLayer.(*OMCI) |
| 255 | assert.True(t, ok) |
| 256 | assert.Equal(t, uint16(0x0004), omciMsg.TransactionID) |
| 257 | assert.Equal(t, StartSoftwareDownloadResponseType, omciMsg.MessageType) |
| 258 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 259 | assert.Equal(t, uint16(3), omciMsg.Length) |
| 260 | |
| 261 | msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadResponse) |
| 262 | |
| 263 | assert.NotNil(t, msgLayer) |
| 264 | |
| 265 | response, ok2 := msgLayer.(*StartSoftwareDownloadResponse) |
| 266 | assert.True(t, ok2) |
| 267 | assert.NotNil(t, response) |
| 268 | assert.Equal(t, me.Success, response.Result) |
| 269 | assert.Equal(t, uint8(0xff), response.WindowSize) |
| 270 | assert.Equal(t, uint8(0), response.NumberOfInstances) |
| 271 | assert.Nil(t, response.MeResults) |
| 272 | |
| 273 | // Verify string output for message |
| 274 | packetString := packet.String() |
| 275 | assert.NotZero(t, len(packetString)) |
| 276 | } |
| 277 | |
| 278 | func TestStartSoftwareDownloadResponseSerialize(t *testing.T) { |
| 279 | goodMessage := "0001330a0007000100ff00000000000000000000000000000000000000000000000000000000000000000028" |
| 280 | |
| 281 | omciLayer := &OMCI{ |
| 282 | TransactionID: 0x01, |
| 283 | MessageType: StartSoftwareDownloadResponseType, |
| 284 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 285 | // Length: 0x28, // Optional, defaults to 40 octets |
| 286 | } |
| 287 | request := &StartSoftwareDownloadResponse{ |
| 288 | MeBasePacket: MeBasePacket{ |
| 289 | EntityClass: me.SoftwareImageClassID, |
| 290 | EntityInstance: 1, |
| 291 | }, |
| 292 | Result: me.Success, |
| 293 | WindowSize: 0xff, |
| 294 | NumberOfInstances: 0, // Note: Optional since default is zero |
| 295 | MeResults: nil, // Note: Optional since default is nil |
| 296 | } |
| 297 | // Test serialization back to former string |
| 298 | var options gopacket.SerializeOptions |
| 299 | options.FixLengths = true |
| 300 | |
| 301 | buffer := gopacket.NewSerializeBuffer() |
| 302 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 303 | assert.NoError(t, err) |
| 304 | |
| 305 | outgoingPacket := buffer.Bytes() |
| 306 | reconstituted := packetToString(outgoingPacket) |
| 307 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 308 | } |
| 309 | |
| 310 | func TestStartSoftwareDownloadResponseZeroTICSerialize(t *testing.T) { |
| 311 | omciLayer := &OMCI{ |
| 312 | TransactionID: 0x0, |
| 313 | MessageType: StartSoftwareDownloadResponseType, |
| 314 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 315 | // Length: 0x28, // Optional, defaults to 40 octets |
| 316 | } |
| 317 | request := &StartSoftwareDownloadResponse{ |
| 318 | MeBasePacket: MeBasePacket{ |
| 319 | EntityClass: me.SoftwareImageClassID, |
| 320 | EntityInstance: 1, |
| 321 | }, |
| 322 | Result: me.Success, |
| 323 | WindowSize: 0xff, |
| 324 | NumberOfInstances: 0, // Note: Optional since default is zero |
| 325 | MeResults: nil, // Note: Optional since default is nil |
| 326 | } |
| 327 | // Test serialization back to former string |
| 328 | var options gopacket.SerializeOptions |
| 329 | options.FixLengths = true |
| 330 | |
| 331 | buffer := gopacket.NewSerializeBuffer() |
| 332 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 333 | assert.Error(t, err) |
| 334 | } |
| 335 | |
| 336 | func TestStartSoftwareDownloadResponseSerializeExtended(t *testing.T) { |
| 337 | goodMessage := "0001330b00070001000300ff00" |
| 338 | |
| 339 | omciLayer := &OMCI{ |
| 340 | TransactionID: 0x01, |
| 341 | MessageType: StartSoftwareDownloadResponseType, |
| 342 | DeviceIdentifier: ExtendedIdent, |
| 343 | } |
| 344 | request := &StartSoftwareDownloadResponse{ |
| 345 | MeBasePacket: MeBasePacket{ |
| 346 | EntityClass: me.SoftwareImageClassID, |
| 347 | EntityInstance: 1, |
| 348 | Extended: true, |
| 349 | }, |
| 350 | Result: me.Success, |
| 351 | WindowSize: 0xff, |
| 352 | NumberOfInstances: 0, // Note: Optional since default is zero |
| 353 | MeResults: nil, // Note: Optional since default is nil |
| 354 | } |
| 355 | // Test serialization back to former string |
| 356 | var options gopacket.SerializeOptions |
| 357 | options.FixLengths = true |
| 358 | |
| 359 | buffer := gopacket.NewSerializeBuffer() |
| 360 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 361 | assert.NoError(t, err) |
| 362 | |
| 363 | outgoingPacket := buffer.Bytes() |
| 364 | reconstituted := packetToString(outgoingPacket) |
| 365 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 366 | } |
| 367 | |
| 368 | func TestDownloadSectionRequestDecodeNoResponseExpected(t *testing.T) { |
| 369 | goodMessage := "0008140a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 370 | data, err := stringToPacket(goodMessage) |
| 371 | assert.NoError(t, err) |
| 372 | |
| 373 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 374 | assert.NotNil(t, packet) |
| 375 | |
| 376 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 377 | assert.NotNil(t, omciLayer) |
| 378 | |
| 379 | omciMsg, ok := omciLayer.(*OMCI) |
| 380 | assert.True(t, ok) |
| 381 | assert.NotNil(t, omciMsg) |
| 382 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 383 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 384 | assert.Equal(t, LayerTypeDownloadSectionRequest, omciMsg.NextLayerType()) |
| 385 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 386 | assert.Equal(t, DownloadSectionRequestType, omciMsg.MessageType) |
| 387 | assert.False(t, omciMsg.ResponseExpected) |
| 388 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 389 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 390 | |
| 391 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 392 | assert.NotNil(t, msgLayer) |
| 393 | |
| 394 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 395 | assert.True(t, ok2) |
| 396 | assert.NotNil(t, request) |
| 397 | assert.Equal(t, LayerTypeDownloadSectionRequest, request.LayerType()) |
| 398 | assert.Equal(t, LayerTypeDownloadSectionRequest, request.CanDecode()) |
| 399 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 400 | assert.Equal(t, uint8(0xcc), request.SectionNumber) |
| 401 | assert.Equal(t, MaxDownloadSectionLength, len(request.SectionData)) |
| 402 | |
| 403 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 404 | assert.Nil(t, genErr) |
| 405 | assert.NotNil(t, sectionData) |
| 406 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
| 407 | assert.Equal(t, sectionData, request.SectionData[:]) |
| 408 | |
| 409 | // Verify string output for message |
| 410 | packetString := packet.String() |
| 411 | assert.NotZero(t, len(packetString)) |
| 412 | } |
| 413 | |
| 414 | func TestDownloadSectionRequestDecodeResponseExpected(t *testing.T) { |
| 415 | goodMessage := "0008540a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 416 | data, err := stringToPacket(goodMessage) |
| 417 | assert.NoError(t, err) |
| 418 | |
| 419 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 420 | assert.NotNil(t, packet) |
| 421 | |
| 422 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 423 | assert.NotNil(t, omciLayer) |
| 424 | |
| 425 | omciMsg, ok := omciLayer.(*OMCI) |
| 426 | assert.True(t, ok) |
| 427 | assert.NotNil(t, omciMsg) |
| 428 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 429 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 430 | assert.Equal(t, LayerTypeDownloadSectionLastRequest, omciMsg.NextLayerType()) |
| 431 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 432 | assert.Equal(t, DownloadSectionRequestWithResponseType, omciMsg.MessageType) |
| 433 | assert.True(t, omciMsg.ResponseExpected) |
| 434 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 435 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 436 | |
| 437 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 438 | assert.NotNil(t, msgLayer) |
| 439 | |
| 440 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 441 | assert.True(t, ok2) |
| 442 | assert.NotNil(t, request) |
| 443 | assert.Equal(t, LayerTypeDownloadSectionRequest, request.LayerType()) |
| 444 | assert.Equal(t, LayerTypeDownloadSectionRequest, request.CanDecode()) |
| 445 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 446 | assert.Equal(t, uint8(0xcc), request.SectionNumber) |
| 447 | assert.Equal(t, 31, len(request.SectionData)) |
| 448 | |
| 449 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 450 | assert.Nil(t, genErr) |
| 451 | assert.NotNil(t, sectionData) |
| 452 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
| 453 | assert.Equal(t, sectionData, request.SectionData[:]) |
| 454 | |
| 455 | // Verify string output for message |
| 456 | packetString := packet.String() |
| 457 | assert.NotZero(t, len(packetString)) |
| 458 | } |
| 459 | |
| 460 | func TestDownloadSectionRequestSerializeNoResponseExpected(t *testing.T) { |
| 461 | goodMessage := "0123140a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 462 | |
| 463 | omciLayer := &OMCI{ |
| 464 | TransactionID: 0x0123, |
| 465 | MessageType: DownloadSectionRequestType, |
| 466 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 467 | // Length: 0x28, // Optional, defaults to 40 octets |
| 468 | } |
| 469 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 470 | assert.Nil(t, genErr) |
| 471 | assert.NotNil(t, sectionData) |
| 472 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
| 473 | |
| 474 | request := &DownloadSectionRequest{ |
| 475 | MeBasePacket: MeBasePacket{ |
| 476 | EntityClass: me.SoftwareImageClassID, |
| 477 | // Default Instance ID is 0 |
| 478 | }, |
| 479 | SectionNumber: 0xcc, |
| 480 | SectionData: sectionData, |
| 481 | } |
| 482 | // Test serialization back to former string |
| 483 | var options gopacket.SerializeOptions |
| 484 | options.FixLengths = true |
| 485 | |
| 486 | buffer := gopacket.NewSerializeBuffer() |
| 487 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 488 | assert.NoError(t, err) |
| 489 | |
| 490 | outgoingPacket := buffer.Bytes() |
| 491 | reconstituted := packetToString(outgoingPacket) |
| 492 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 493 | } |
| 494 | |
| 495 | func TestDownloadSectionRequestSerializeNoResponsePartialDataExpected(t *testing.T) { |
| 496 | // If a small buffer is provided, serialize will now zero extend the baseline format |
| 497 | goodMessage := "0123140a00070000cc0102030405060708091011121314151617181920212223242526272829000000000028" |
| 498 | |
| 499 | omciLayer := &OMCI{ |
| 500 | TransactionID: 0x0123, |
| 501 | MessageType: DownloadSectionRequestType, |
| 502 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 503 | // Length: 0x28, // Optional, defaults to 40 octets |
| 504 | } |
| 505 | sectionData, genErr := stringToPacket("0102030405060708091011121314151617181920212223242526272829") |
| 506 | assert.Nil(t, genErr) |
| 507 | assert.NotNil(t, sectionData) |
| 508 | assert.Equal(t, MaxDownloadSectionLength-2, len(sectionData)) // Partial data buffer |
| 509 | |
| 510 | request := &DownloadSectionRequest{ |
| 511 | MeBasePacket: MeBasePacket{ |
| 512 | EntityClass: me.SoftwareImageClassID, |
| 513 | // Default Instance ID is 0 |
| 514 | }, |
| 515 | SectionNumber: 0xcc, |
| 516 | SectionData: sectionData, |
| 517 | } |
| 518 | // Test serialization back to former string |
| 519 | var options gopacket.SerializeOptions |
| 520 | options.FixLengths = true |
| 521 | |
| 522 | buffer := gopacket.NewSerializeBuffer() |
| 523 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 524 | assert.NoError(t, err) |
| 525 | |
| 526 | outgoingPacket := buffer.Bytes() |
| 527 | reconstituted := packetToString(outgoingPacket) |
| 528 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 529 | } |
| 530 | |
| 531 | func TestDownloadSectionRequestSerializeResponseExpectedMethod1(t *testing.T) { |
| 532 | goodMessage := "2468540a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 533 | |
| 534 | omciLayer := &OMCI{ |
| 535 | TransactionID: 0x2468, |
| 536 | MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType |
| 537 | ResponseExpected: true, |
| 538 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 539 | // Length: 0x28, // Optional, defaults to 40 octets |
| 540 | } |
| 541 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 542 | assert.Nil(t, genErr) |
| 543 | assert.NotNil(t, sectionData) |
| 544 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
| 545 | |
| 546 | request := &DownloadSectionRequest{ |
| 547 | MeBasePacket: MeBasePacket{ |
| 548 | EntityClass: me.SoftwareImageClassID, |
| 549 | // Default Instance ID is 0 |
| 550 | }, |
| 551 | SectionNumber: 0xcc, |
| 552 | SectionData: sectionData, |
| 553 | } |
| 554 | // Test serialization back to former string |
| 555 | var options gopacket.SerializeOptions |
| 556 | options.FixLengths = true |
| 557 | |
| 558 | buffer := gopacket.NewSerializeBuffer() |
| 559 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 560 | assert.NoError(t, err) |
| 561 | |
| 562 | outgoingPacket := buffer.Bytes() |
| 563 | reconstituted := packetToString(outgoingPacket) |
| 564 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 565 | } |
| 566 | |
| 567 | func TestDownloadSectionRequestSerializeResponseExpectedMethod2(t *testing.T) { |
| 568 | goodMessage := "2468540a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028" |
| 569 | |
| 570 | // In this case, just use the request type with AR response requested already encoded |
| 571 | omciLayer := &OMCI{ |
| 572 | TransactionID: 0x2468, |
| 573 | MessageType: DownloadSectionRequestWithResponseType, |
| 574 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 575 | // Length: 0x28, // Optional, defaults to 40 octets |
| 576 | } |
| 577 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 578 | assert.Nil(t, genErr) |
| 579 | assert.NotNil(t, sectionData) |
| 580 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
| 581 | |
| 582 | request := &DownloadSectionRequest{ |
| 583 | MeBasePacket: MeBasePacket{ |
| 584 | EntityClass: me.SoftwareImageClassID, |
| 585 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
| 586 | }, |
| 587 | SectionNumber: 0xcc, |
| 588 | SectionData: sectionData, |
| 589 | } |
| 590 | // Test serialization back to former string |
| 591 | var options gopacket.SerializeOptions |
| 592 | options.FixLengths = true |
| 593 | |
| 594 | buffer := gopacket.NewSerializeBuffer() |
| 595 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 596 | assert.NoError(t, err) |
| 597 | |
| 598 | outgoingPacket := buffer.Bytes() |
| 599 | reconstituted := packetToString(outgoingPacket) |
| 600 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 601 | } |
| 602 | |
| 603 | func TestDownloadSectionRequestSerializeResponseExpectedZeroTICMethod1(t *testing.T) { |
| 604 | omciLayer := &OMCI{ |
| 605 | TransactionID: 0x0, |
| 606 | MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType |
| 607 | ResponseExpected: true, |
| 608 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 609 | // Length: 0x28, // Optional, defaults to 40 octets |
| 610 | } |
| 611 | sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031") |
| 612 | assert.Nil(t, genErr) |
| 613 | assert.NotNil(t, sectionData) |
| 614 | assert.Equal(t, MaxDownloadSectionLength, len(sectionData)) |
| 615 | |
| 616 | request := &DownloadSectionRequest{ |
| 617 | MeBasePacket: MeBasePacket{ |
| 618 | EntityClass: me.SoftwareImageClassID, |
| 619 | // Default Instance ID is 0 |
| 620 | }, |
| 621 | SectionNumber: 0xcc, |
| 622 | SectionData: sectionData, |
| 623 | } |
| 624 | // Test serialization back to former string |
| 625 | var options gopacket.SerializeOptions |
| 626 | options.FixLengths = true |
| 627 | |
| 628 | buffer := gopacket.NewSerializeBuffer() |
| 629 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 630 | assert.Error(t, err) |
| 631 | } |
| 632 | |
| 633 | func TestExtendedDownloadSectionRequestDecodeNoResponseExpected(t *testing.T) { |
| 634 | goodMessage := "0008140b00070001" |
| 635 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 636 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 637 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 638 | sectionNumber := 0x88 |
| 639 | length := 1 + (8 * 25) |
| 640 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 641 | goodMessage += hdr + payloadTotal |
| 642 | data, err := stringToPacket(goodMessage) |
| 643 | assert.NoError(t, err) |
| 644 | |
| 645 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 646 | assert.NotNil(t, packet) |
| 647 | assert.Nil(t, packet.ErrorLayer()) |
| 648 | |
| 649 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 650 | assert.NotNil(t, omciLayer) |
| 651 | |
| 652 | omciMsg, ok := omciLayer.(*OMCI) |
| 653 | assert.True(t, ok) |
| 654 | assert.NotNil(t, omciMsg) |
| 655 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 656 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 657 | assert.Equal(t, LayerTypeDownloadSectionRequest, omciMsg.NextLayerType()) |
| 658 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 659 | assert.Equal(t, DownloadSectionRequestType, omciMsg.MessageType) |
| 660 | assert.False(t, omciMsg.ResponseExpected) |
| 661 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 662 | assert.Equal(t, uint16(length), omciMsg.Length) |
| 663 | |
| 664 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 665 | assert.NotNil(t, msgLayer) |
| 666 | |
| 667 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 668 | assert.True(t, ok2) |
| 669 | assert.NotNil(t, request) |
| 670 | assert.Equal(t, LayerTypeDownloadSectionRequest, request.LayerType()) |
| 671 | assert.Equal(t, LayerTypeDownloadSectionRequest, request.CanDecode()) |
| 672 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 673 | assert.Equal(t, uint8(sectionNumber), request.SectionNumber) |
| 674 | assert.Equal(t, length-1, len(request.SectionData)) |
| 675 | |
| 676 | data, err = stringToPacket(payloadTotal) |
| 677 | assert.NoError(t, err) |
| 678 | assert.Equal(t, data, request.SectionData[:]) |
| 679 | |
| 680 | // Verify string output for message |
| 681 | packetString := packet.String() |
| 682 | assert.NotZero(t, len(packetString)) |
| 683 | } |
| 684 | |
| 685 | func TestExtendedDownloadSectionRequestDecodeResponseExpected(t *testing.T) { |
| 686 | goodMessage := "0008540b00070001" |
| 687 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 688 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 689 | payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 690 | payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 691 | payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 692 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 693 | sectionNumber := 0x88 |
| 694 | length := 1 + (20 * 25) |
| 695 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 696 | goodMessage += hdr + payloadTotal |
| 697 | data, err := stringToPacket(goodMessage) |
| 698 | assert.NoError(t, err) |
| 699 | |
| 700 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 701 | assert.NotNil(t, packet) |
| 702 | assert.Nil(t, packet.ErrorLayer()) |
| 703 | |
| 704 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 705 | assert.NotNil(t, omciLayer) |
| 706 | |
| 707 | omciMsg, ok := omciLayer.(*OMCI) |
| 708 | assert.True(t, ok) |
| 709 | assert.Equal(t, uint16(0x0008), omciMsg.TransactionID) |
| 710 | assert.Equal(t, DownloadSectionRequestWithResponseType, omciMsg.MessageType) |
| 711 | assert.True(t, omciMsg.ResponseExpected) |
| 712 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 713 | assert.Equal(t, uint16(length), omciMsg.Length) |
| 714 | |
| 715 | msgLayer := packet.Layer(LayerTypeDownloadSectionRequest) |
| 716 | assert.NotNil(t, msgLayer) |
| 717 | |
| 718 | request, ok2 := msgLayer.(*DownloadSectionRequest) |
| 719 | assert.True(t, ok2) |
| 720 | assert.NotNil(t, request) |
| 721 | assert.Equal(t, uint8(sectionNumber), request.SectionNumber) |
| 722 | assert.Equal(t, length-1, len(request.SectionData)) |
| 723 | |
| 724 | data, err = stringToPacket(payloadTotal) |
| 725 | assert.NoError(t, err) |
| 726 | assert.Equal(t, data, request.SectionData) |
| 727 | |
| 728 | // Verify string output for message |
| 729 | packetString := packet.String() |
| 730 | assert.NotZero(t, len(packetString)) |
| 731 | } |
| 732 | |
| 733 | func TestExtendedDownloadSectionRequestSerializeNoResponseExpected(t *testing.T) { |
| 734 | goodMessage := "0123140b00070001" |
| 735 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 736 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 737 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 738 | sectionNumber := 0x84 |
| 739 | length := 1 + (8 * 25) |
| 740 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 741 | goodMessage += hdr + payloadTotal |
| 742 | |
| 743 | omciLayer := &OMCI{ |
| 744 | TransactionID: 0x0123, |
| 745 | MessageType: DownloadSectionRequestType, |
| 746 | DeviceIdentifier: ExtendedIdent, |
| 747 | } |
| 748 | sectionData, genErr := stringToPacket(payloadTotal) |
| 749 | assert.Nil(t, genErr) |
| 750 | assert.NotNil(t, sectionData) |
| 751 | assert.Equal(t, len(payloadTotal)/2, len(sectionData)) |
| 752 | |
| 753 | request := &DownloadSectionRequest{ |
| 754 | MeBasePacket: MeBasePacket{ |
| 755 | EntityClass: me.SoftwareImageClassID, |
| 756 | EntityInstance: uint16(1), |
| 757 | Extended: true, |
| 758 | }, |
| 759 | SectionNumber: byte(sectionNumber), |
| 760 | SectionData: sectionData, |
| 761 | } |
| 762 | // Test serialization back to former string |
| 763 | var options gopacket.SerializeOptions |
| 764 | options.FixLengths = true |
| 765 | |
| 766 | buffer := gopacket.NewSerializeBuffer() |
| 767 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 768 | assert.NoError(t, err) |
| 769 | |
| 770 | outgoingPacket := buffer.Bytes() |
| 771 | reconstituted := packetToString(outgoingPacket) |
| 772 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 773 | } |
| 774 | |
| 775 | func TestExtendedDownloadSectionRequestSerializeResponseExpectedMethod1(t *testing.T) { |
| 776 | goodMessage := "2468540b00070001" |
| 777 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 778 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 779 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 780 | sectionNumber := 0x84 |
| 781 | length := 1 + (8 * 25) |
| 782 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 783 | goodMessage += hdr + payloadTotal |
| 784 | |
| 785 | omciLayer := &OMCI{ |
| 786 | TransactionID: 0x2468, |
| 787 | MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType |
| 788 | ResponseExpected: true, |
| 789 | DeviceIdentifier: ExtendedIdent, |
| 790 | } |
| 791 | sectionData, genErr := stringToPacket(payloadTotal) |
| 792 | assert.Nil(t, genErr) |
| 793 | assert.NotNil(t, sectionData) |
| 794 | assert.Equal(t, len(payloadTotal)/2, len(sectionData)) |
| 795 | |
| 796 | request := &DownloadSectionRequest{ |
| 797 | MeBasePacket: MeBasePacket{ |
| 798 | EntityClass: me.SoftwareImageClassID, |
| 799 | EntityInstance: uint16(1), |
| 800 | Extended: true, |
| 801 | }, |
| 802 | SectionNumber: byte(sectionNumber), |
| 803 | SectionData: sectionData, |
| 804 | } |
| 805 | // Test serialization back to former string |
| 806 | var options gopacket.SerializeOptions |
| 807 | options.FixLengths = true |
| 808 | |
| 809 | buffer := gopacket.NewSerializeBuffer() |
| 810 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 811 | assert.NoError(t, err) |
| 812 | |
| 813 | outgoingPacket := buffer.Bytes() |
| 814 | reconstituted := packetToString(outgoingPacket) |
| 815 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 816 | } |
| 817 | |
| 818 | func TestExtendedDownloadSectionRequestSerializeResponseExpectedMethod2(t *testing.T) { |
| 819 | goodMessage := "2468540b00070001" |
| 820 | payloadFragment := "01020304050607080910111213141516171819202122232425" |
| 821 | payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment + |
| 822 | payloadFragment + payloadFragment + payloadFragment + payloadFragment |
| 823 | sectionNumber := 0x84 |
| 824 | length := 1 + (8 * 25) |
| 825 | hdr := fmt.Sprintf("%04x%02x", length, sectionNumber) |
| 826 | goodMessage += hdr + payloadTotal |
| 827 | |
| 828 | // In this case, just use the request type with AR response requested already encoded |
| 829 | omciLayer := &OMCI{ |
| 830 | TransactionID: 0x2468, |
| 831 | MessageType: DownloadSectionRequestWithResponseType, |
| 832 | ResponseExpected: true, |
| 833 | DeviceIdentifier: ExtendedIdent, |
| 834 | } |
| 835 | sectionData, genErr := stringToPacket(payloadTotal) |
| 836 | assert.Nil(t, genErr) |
| 837 | assert.NotNil(t, sectionData) |
| 838 | assert.Equal(t, len(payloadTotal)/2, len(sectionData)) |
| 839 | |
| 840 | request := &DownloadSectionRequest{ |
| 841 | MeBasePacket: MeBasePacket{ |
| 842 | EntityClass: me.SoftwareImageClassID, |
| 843 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
| 844 | Extended: true, |
| 845 | }, |
| 846 | SectionNumber: byte(sectionNumber), |
| 847 | SectionData: sectionData, |
| 848 | } |
| 849 | // Test serialization back to former string |
| 850 | var options gopacket.SerializeOptions |
| 851 | options.FixLengths = true |
| 852 | |
| 853 | buffer := gopacket.NewSerializeBuffer() |
| 854 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 855 | assert.NoError(t, err) |
| 856 | |
| 857 | outgoingPacket := buffer.Bytes() |
| 858 | reconstituted := packetToString(outgoingPacket) |
| 859 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 860 | } |
| 861 | |
| 862 | func TestExtendedDownloadSectionRequestDecodeTruncated(t *testing.T) { |
| 863 | goodMessage := "0008540b000700010000" |
| 864 | data, err := stringToPacket(goodMessage) |
| 865 | assert.NoError(t, err) |
| 866 | |
| 867 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 868 | assert.NotNil(t, packet) |
| 869 | |
| 870 | failure := packet.ErrorLayer() |
| 871 | assert.NotNil(t, failure) |
| 872 | |
| 873 | decodeFailure, ok := failure.(*gopacket.DecodeFailure) |
| 874 | assert.True(t, ok) |
| 875 | assert.NotNil(t, decodeFailure) |
| 876 | assert.NotNil(t, decodeFailure.String()) |
| 877 | assert.True(t, len(decodeFailure.String()) > 0) |
| 878 | assert.Equal(t, gopacket.LayerTypeDecodeFailure, decodeFailure.LayerType()) |
| 879 | |
| 880 | metadata := packet.Metadata() |
| 881 | assert.NotNil(t, metadata) |
| 882 | assert.True(t, metadata.Truncated) |
| 883 | |
| 884 | // Verify string output for message |
| 885 | packetString := packet.String() |
| 886 | assert.NotZero(t, len(packetString)) |
| 887 | } |
| 888 | |
| 889 | func TestDownloadSectionResponseDecode(t *testing.T) { |
| 890 | goodMessage := "0022340a00070001061f00000000000000000000000000000000000000000000000000000000000000000028" |
| 891 | data, err := stringToPacket(goodMessage) |
| 892 | assert.NoError(t, err) |
| 893 | |
| 894 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 895 | assert.NotNil(t, packet) |
| 896 | |
| 897 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 898 | assert.NotNil(t, omciLayer) |
| 899 | |
| 900 | omciMsg, ok := omciLayer.(*OMCI) |
| 901 | assert.True(t, ok) |
| 902 | assert.NotNil(t, omciMsg) |
| 903 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 904 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 905 | assert.Equal(t, LayerTypeDownloadSectionResponse, omciMsg.NextLayerType()) |
| 906 | assert.Equal(t, uint16(0x0022), omciMsg.TransactionID) |
| 907 | assert.Equal(t, DownloadSectionResponseType, omciMsg.MessageType) |
| 908 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 909 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 910 | |
| 911 | msgLayer := packet.Layer(LayerTypeDownloadSectionResponse) |
| 912 | |
| 913 | assert.NotNil(t, msgLayer) |
| 914 | |
| 915 | response, ok2 := msgLayer.(*DownloadSectionResponse) |
| 916 | assert.True(t, ok2) |
| 917 | assert.NotNil(t, response) |
| 918 | assert.Equal(t, LayerTypeDownloadSectionResponse, response.LayerType()) |
| 919 | assert.Equal(t, LayerTypeDownloadSectionResponse, response.CanDecode()) |
| 920 | assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType()) |
| 921 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 922 | assert.Equal(t, byte(0x1f), response.SectionNumber) |
| 923 | |
| 924 | // Verify string output for message |
| 925 | packetString := packet.String() |
| 926 | assert.NotZero(t, len(packetString)) |
| 927 | } |
| 928 | |
| 929 | func TestDownloadSectionResponseDecodeExtended(t *testing.T) { |
| 930 | goodMessage := "0022340b000700010002061f" |
| 931 | data, err := stringToPacket(goodMessage) |
| 932 | assert.NoError(t, err) |
| 933 | |
| 934 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 935 | assert.NotNil(t, packet) |
| 936 | |
| 937 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 938 | assert.NotNil(t, omciLayer) |
| 939 | |
| 940 | omciMsg, ok := omciLayer.(*OMCI) |
| 941 | assert.True(t, ok) |
| 942 | assert.NotNil(t, omciMsg) |
| 943 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 944 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 945 | assert.Equal(t, LayerTypeDownloadSectionResponse, omciMsg.NextLayerType()) |
| 946 | assert.Equal(t, uint16(0x0022), omciMsg.TransactionID) |
| 947 | assert.Equal(t, DownloadSectionResponseType, omciMsg.MessageType) |
| 948 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 949 | assert.Equal(t, uint16(2), omciMsg.Length) |
| 950 | |
| 951 | msgLayer := packet.Layer(LayerTypeDownloadSectionResponse) |
| 952 | assert.NotNil(t, msgLayer) |
| 953 | |
| 954 | response, ok2 := msgLayer.(*DownloadSectionResponse) |
| 955 | assert.True(t, ok2) |
| 956 | assert.NotNil(t, response) |
| 957 | assert.Equal(t, LayerTypeDownloadSectionResponse, response.LayerType()) |
| 958 | assert.Equal(t, LayerTypeDownloadSectionResponse, response.CanDecode()) |
| 959 | assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType()) |
| 960 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 961 | assert.Equal(t, byte(0x1f), response.SectionNumber) |
| 962 | |
| 963 | // Verify string output for message |
| 964 | packetString := packet.String() |
| 965 | assert.NotZero(t, len(packetString)) |
| 966 | } |
| 967 | |
| 968 | func TestDownloadSectionResponseDecodeTruncatedExtended(t *testing.T) { |
| 969 | goodMessage := "0022340b00070001000106" |
| 970 | data, err := stringToPacket(goodMessage) |
| 971 | assert.NoError(t, err) |
| 972 | |
| 973 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 974 | assert.NotNil(t, packet) |
| 975 | |
| 976 | failure := packet.ErrorLayer() |
| 977 | assert.NotNil(t, failure) |
| 978 | |
| 979 | decodeFailure, ok := failure.(*gopacket.DecodeFailure) |
| 980 | assert.True(t, ok) |
| 981 | assert.NotNil(t, decodeFailure) |
| 982 | assert.NotNil(t, decodeFailure.String()) |
| 983 | assert.True(t, len(decodeFailure.String()) > 0) |
| 984 | assert.Equal(t, gopacket.LayerTypeDecodeFailure, decodeFailure.LayerType()) |
| 985 | |
| 986 | metadata := packet.Metadata() |
| 987 | assert.NotNil(t, metadata) |
| 988 | assert.True(t, metadata.Truncated) |
| 989 | |
| 990 | // Verify string output for message |
| 991 | packetString := packet.String() |
| 992 | assert.NotZero(t, len(packetString)) |
| 993 | } |
| 994 | |
| 995 | func TestDownloadSectionResponseSerialize(t *testing.T) { |
| 996 | goodMessage := "0022340a00070001061f00000000000000000000000000000000000000000000000000000000000000000028" |
| 997 | |
| 998 | omciLayer := &OMCI{ |
| 999 | TransactionID: 0x0022, |
| 1000 | MessageType: DownloadSectionResponseType, |
| 1001 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1002 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1003 | } |
| 1004 | request := &DownloadSectionResponse{ |
| 1005 | MeBasePacket: MeBasePacket{ |
| 1006 | EntityClass: me.SoftwareImageClassID, |
| 1007 | EntityInstance: 1, |
| 1008 | }, |
| 1009 | Result: me.DeviceBusy, |
| 1010 | SectionNumber: 0x1f, |
| 1011 | } |
| 1012 | // Test serialization back to former string |
| 1013 | var options gopacket.SerializeOptions |
| 1014 | options.FixLengths = true |
| 1015 | |
| 1016 | buffer := gopacket.NewSerializeBuffer() |
| 1017 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1018 | assert.NoError(t, err) |
| 1019 | |
| 1020 | outgoingPacket := buffer.Bytes() |
| 1021 | reconstituted := packetToString(outgoingPacket) |
| 1022 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1023 | } |
| 1024 | |
| 1025 | func TestDownloadSectionResponseZeroTICSerialize(t *testing.T) { |
| 1026 | omciLayer := &OMCI{ |
| 1027 | TransactionID: 0x0, |
| 1028 | MessageType: DownloadSectionResponseType, |
| 1029 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1030 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1031 | } |
| 1032 | request := &DownloadSectionResponse{ |
| 1033 | MeBasePacket: MeBasePacket{ |
| 1034 | EntityClass: me.SoftwareImageClassID, |
| 1035 | EntityInstance: 1, |
| 1036 | }, |
| 1037 | Result: me.DeviceBusy, |
| 1038 | SectionNumber: 0x1f, |
| 1039 | } |
| 1040 | // Test serialization back to former string |
| 1041 | var options gopacket.SerializeOptions |
| 1042 | options.FixLengths = true |
| 1043 | |
| 1044 | buffer := gopacket.NewSerializeBuffer() |
| 1045 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1046 | assert.Error(t, err) |
| 1047 | } |
| 1048 | |
| 1049 | func TestDownloadSectionResponseSerializeExtended(t *testing.T) { |
| 1050 | goodMessage := "0022340b000700010002061f" |
| 1051 | |
| 1052 | omciLayer := &OMCI{ |
| 1053 | TransactionID: 0x0022, |
| 1054 | MessageType: DownloadSectionResponseType, |
| 1055 | DeviceIdentifier: ExtendedIdent, |
| 1056 | } |
| 1057 | request := &DownloadSectionResponse{ |
| 1058 | MeBasePacket: MeBasePacket{ |
| 1059 | EntityClass: me.SoftwareImageClassID, |
| 1060 | EntityInstance: 1, |
| 1061 | Extended: true, |
| 1062 | }, |
| 1063 | Result: me.DeviceBusy, |
| 1064 | SectionNumber: 0x1f, |
| 1065 | } |
| 1066 | // Test serialization back to former string |
| 1067 | var options gopacket.SerializeOptions |
| 1068 | options.FixLengths = true |
| 1069 | |
| 1070 | buffer := gopacket.NewSerializeBuffer() |
| 1071 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1072 | assert.NoError(t, err) |
| 1073 | |
| 1074 | outgoingPacket := buffer.Bytes() |
| 1075 | reconstituted := packetToString(outgoingPacket) |
| 1076 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1077 | } |
| 1078 | |
| 1079 | func TestEndSoftwareDownloadRequestDecode(t *testing.T) { |
| 1080 | // |
| 1081 | // 8100 55 0a 0007 0001 ff92a226 000f4240 01 0001 00000000000000000000000000000000000000000000000028 |
| 1082 | // |
| 1083 | goodMessage := "8100550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028" |
| 1084 | data, err := stringToPacket(goodMessage) |
| 1085 | assert.NoError(t, err) |
| 1086 | |
| 1087 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1088 | assert.NotNil(t, packet) |
| 1089 | |
| 1090 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1091 | assert.NotNil(t, omciLayer) |
| 1092 | |
| 1093 | omciMsg, ok := omciLayer.(*OMCI) |
| 1094 | assert.True(t, ok) |
| 1095 | assert.NotNil(t, omciMsg) |
| 1096 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 1097 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 1098 | assert.Equal(t, LayerTypeEndSoftwareDownloadRequest, omciMsg.NextLayerType()) |
| 1099 | assert.Equal(t, uint16(0x8100), omciMsg.TransactionID) |
| 1100 | assert.Equal(t, EndSoftwareDownloadRequestType, omciMsg.MessageType) |
| 1101 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1102 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1103 | |
| 1104 | msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadRequest) |
| 1105 | assert.NotNil(t, msgLayer) |
| 1106 | |
| 1107 | request, ok2 := msgLayer.(*EndSoftwareDownloadRequest) |
| 1108 | assert.True(t, ok2) |
| 1109 | assert.NotNil(t, request) |
| 1110 | assert.Equal(t, LayerTypeEndSoftwareDownloadRequest, request.LayerType()) |
| 1111 | assert.Equal(t, LayerTypeEndSoftwareDownloadRequest, request.CanDecode()) |
| 1112 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 1113 | assert.Equal(t, uint32(0xff92a226), request.CRC32) |
| 1114 | assert.Equal(t, uint32(0x000f4240), request.ImageSize) |
| 1115 | assert.Equal(t, byte(1), request.NumberOfInstances) |
| 1116 | assert.Equal(t, 1, len(request.ImageInstances)) |
| 1117 | assert.Equal(t, uint16(1), request.ImageInstances[0]) |
| 1118 | |
| 1119 | // Verify string output for message |
| 1120 | packetString := packet.String() |
| 1121 | assert.NotZero(t, len(packetString)) |
| 1122 | } |
| 1123 | |
| 1124 | func TestEndSoftwareDownloadRequestDecodeExtended(t *testing.T) { |
| 1125 | // |
| 1126 | // 8100 55 0a 0007 0001 000b ff92a226 000f4240 01 0001 |
| 1127 | // |
| 1128 | goodMessage := "8100550b00070001000bff92a226000f4240010001" |
| 1129 | data, err := stringToPacket(goodMessage) |
| 1130 | assert.NoError(t, err) |
| 1131 | |
| 1132 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1133 | assert.NotNil(t, packet) |
| 1134 | |
| 1135 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1136 | assert.NotNil(t, omciLayer) |
| 1137 | |
| 1138 | omciMsg, ok := omciLayer.(*OMCI) |
| 1139 | assert.True(t, ok) |
| 1140 | assert.NotNil(t, omciMsg) |
| 1141 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 1142 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 1143 | assert.Equal(t, LayerTypeEndSoftwareDownloadRequest, omciMsg.NextLayerType()) |
| 1144 | assert.Equal(t, uint16(0x8100), omciMsg.TransactionID) |
| 1145 | assert.Equal(t, EndSoftwareDownloadRequestType, omciMsg.MessageType) |
| 1146 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 1147 | assert.Equal(t, uint16(11), omciMsg.Length) |
| 1148 | |
| 1149 | msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadRequest) |
| 1150 | assert.NotNil(t, msgLayer) |
| 1151 | |
| 1152 | request, ok2 := msgLayer.(*EndSoftwareDownloadRequest) |
| 1153 | assert.True(t, ok2) |
| 1154 | assert.NotNil(t, request) |
| 1155 | assert.Equal(t, LayerTypeEndSoftwareDownloadRequest, request.LayerType()) |
| 1156 | assert.Equal(t, LayerTypeEndSoftwareDownloadRequest, request.CanDecode()) |
| 1157 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 1158 | assert.Equal(t, uint32(0xff92a226), request.CRC32) |
| 1159 | assert.Equal(t, uint32(0x000f4240), request.ImageSize) |
| 1160 | assert.Equal(t, byte(1), request.NumberOfInstances) |
| 1161 | assert.Equal(t, 1, len(request.ImageInstances)) |
| 1162 | assert.Equal(t, uint16(1), request.ImageInstances[0]) |
| 1163 | |
| 1164 | // Verify string output for message |
| 1165 | packetString := packet.String() |
| 1166 | assert.NotZero(t, len(packetString)) |
| 1167 | } |
| 1168 | |
| 1169 | func TestEndSoftwareDownloadRequestSerialize(t *testing.T) { |
| 1170 | // 8100 55 0a 0007 0001 ff92a226 000f4240 01 0001 00000000000000000000000000000000000000000000000028 |
| 1171 | goodMessage := "8100550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028" |
| 1172 | |
| 1173 | omciLayer := &OMCI{ |
| 1174 | TransactionID: 0x8100, |
| 1175 | MessageType: EndSoftwareDownloadRequestType, |
| 1176 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1177 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1178 | } |
| 1179 | request := &EndSoftwareDownloadRequest{ |
| 1180 | MeBasePacket: MeBasePacket{ |
| 1181 | EntityClass: me.SoftwareImageClassID, |
| 1182 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
| 1183 | }, |
| 1184 | CRC32: 0xff92a226, |
| 1185 | ImageSize: 1000000, |
| 1186 | NumberOfInstances: 1, |
| 1187 | ImageInstances: []uint16{1}, |
| 1188 | } |
| 1189 | // Test serialization back to former string |
| 1190 | var options gopacket.SerializeOptions |
| 1191 | options.FixLengths = true |
| 1192 | |
| 1193 | buffer := gopacket.NewSerializeBuffer() |
| 1194 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1195 | assert.NoError(t, err) |
| 1196 | |
| 1197 | outgoingPacket := buffer.Bytes() |
| 1198 | reconstituted := packetToString(outgoingPacket) |
| 1199 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1200 | } |
| 1201 | |
| 1202 | func TestEndSoftwareDownloadRequestZeroTICSerialize(t *testing.T) { |
| 1203 | // 8100 55 0a 0007 0001 ff92a226 000f4240 01 0001 00000000000000000000000000000000000000000000000028 |
| 1204 | omciLayer := &OMCI{ |
| 1205 | TransactionID: 0x0, |
| 1206 | MessageType: EndSoftwareDownloadRequestType, |
| 1207 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1208 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1209 | } |
| 1210 | request := &EndSoftwareDownloadRequest{ |
| 1211 | MeBasePacket: MeBasePacket{ |
| 1212 | EntityClass: me.SoftwareImageClassID, |
| 1213 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
| 1214 | }, |
| 1215 | CRC32: 0xff92a226, |
| 1216 | ImageSize: 1000000, |
| 1217 | NumberOfInstances: 1, |
| 1218 | ImageInstances: []uint16{1}, |
| 1219 | } |
| 1220 | // Test serialization back to former string |
| 1221 | var options gopacket.SerializeOptions |
| 1222 | options.FixLengths = true |
| 1223 | |
| 1224 | buffer := gopacket.NewSerializeBuffer() |
| 1225 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1226 | assert.Error(t, err) |
| 1227 | } |
| 1228 | |
| 1229 | func TestEndSoftwareDownloadRequestSerializeExtended(t *testing.T) { |
| 1230 | goodMessage := "8100550b00070001000bff92a226000f4240010001" |
| 1231 | |
| 1232 | omciLayer := &OMCI{ |
| 1233 | TransactionID: 0x8100, |
| 1234 | MessageType: EndSoftwareDownloadRequestType, |
| 1235 | DeviceIdentifier: ExtendedIdent, |
| 1236 | } |
| 1237 | request := &EndSoftwareDownloadRequest{ |
| 1238 | MeBasePacket: MeBasePacket{ |
| 1239 | EntityClass: me.SoftwareImageClassID, |
| 1240 | EntityInstance: 0x0001, // Default is zero, here we want image 1 |
| 1241 | Extended: true, |
| 1242 | }, |
| 1243 | CRC32: 0xff92a226, |
| 1244 | ImageSize: 1000000, |
| 1245 | NumberOfInstances: 1, |
| 1246 | ImageInstances: []uint16{1}, |
| 1247 | } |
| 1248 | // Test serialization back to former string |
| 1249 | var options gopacket.SerializeOptions |
| 1250 | options.FixLengths = true |
| 1251 | |
| 1252 | buffer := gopacket.NewSerializeBuffer() |
| 1253 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1254 | assert.NoError(t, err) |
| 1255 | |
| 1256 | outgoingPacket := buffer.Bytes() |
| 1257 | reconstituted := packetToString(outgoingPacket) |
| 1258 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1259 | } |
| 1260 | |
| 1261 | func TestEndSoftwareDownloadResponseDecode(t *testing.T) { |
| 1262 | // 8123 35 0a 0007 0001 06 0000000000000000000000000000000000000000000000000000000000000000000028 |
| 1263 | goodMessage := "8123350a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 1264 | data, err := stringToPacket(goodMessage) |
| 1265 | assert.NoError(t, err) |
| 1266 | |
| 1267 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1268 | assert.NotNil(t, packet) |
| 1269 | |
| 1270 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1271 | assert.NotNil(t, omciLayer) |
| 1272 | |
| 1273 | omciMsg, ok := omciLayer.(*OMCI) |
| 1274 | assert.True(t, ok) |
| 1275 | assert.NotNil(t, omciMsg) |
| 1276 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 1277 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 1278 | assert.Equal(t, LayerTypeEndSoftwareDownloadResponse, omciMsg.NextLayerType()) |
| 1279 | assert.Equal(t, uint16(0x8123), omciMsg.TransactionID) |
| 1280 | assert.Equal(t, EndSoftwareDownloadResponseType, omciMsg.MessageType) |
| 1281 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1282 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1283 | |
| 1284 | msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadResponse) |
| 1285 | assert.NotNil(t, msgLayer) |
| 1286 | |
| 1287 | response, ok2 := msgLayer.(*EndSoftwareDownloadResponse) |
| 1288 | assert.True(t, ok2) |
| 1289 | assert.NotNil(t, response) |
| 1290 | assert.Equal(t, LayerTypeEndSoftwareDownloadResponse, response.LayerType()) |
| 1291 | assert.Equal(t, LayerTypeEndSoftwareDownloadResponse, response.CanDecode()) |
| 1292 | assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType()) |
| 1293 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 1294 | assert.Equal(t, byte(0), response.NumberOfInstances) |
| 1295 | assert.Nil(t, response.MeResults) |
| 1296 | |
| 1297 | // Verify string output for message |
| 1298 | packetString := packet.String() |
| 1299 | assert.NotZero(t, len(packetString)) |
| 1300 | } |
| 1301 | |
| 1302 | func TestEndSoftwareDownloadResponseDecodeExtended(t *testing.T) { |
| 1303 | goodMessage := "8123350b0007000100020600" |
| 1304 | data, err := stringToPacket(goodMessage) |
| 1305 | assert.NoError(t, err) |
| 1306 | |
| 1307 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1308 | assert.NotNil(t, packet) |
| 1309 | |
| 1310 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1311 | assert.NotNil(t, omciLayer) |
| 1312 | |
| 1313 | omciMsg, ok := omciLayer.(*OMCI) |
| 1314 | assert.True(t, ok) |
| 1315 | assert.NotNil(t, omciMsg) |
| 1316 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 1317 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 1318 | assert.Equal(t, LayerTypeEndSoftwareDownloadResponse, omciMsg.NextLayerType()) |
| 1319 | assert.Equal(t, uint16(0x8123), omciMsg.TransactionID) |
| 1320 | assert.Equal(t, EndSoftwareDownloadResponseType, omciMsg.MessageType) |
| 1321 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 1322 | assert.Equal(t, uint16(2), omciMsg.Length) |
| 1323 | |
| 1324 | msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadResponse) |
| 1325 | assert.NotNil(t, msgLayer) |
| 1326 | |
| 1327 | response, ok2 := msgLayer.(*EndSoftwareDownloadResponse) |
| 1328 | assert.True(t, ok2) |
| 1329 | assert.NotNil(t, response) |
| 1330 | assert.Equal(t, LayerTypeEndSoftwareDownloadResponse, response.LayerType()) |
| 1331 | assert.Equal(t, LayerTypeEndSoftwareDownloadResponse, response.CanDecode()) |
| 1332 | assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType()) |
| 1333 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 1334 | assert.Equal(t, byte(0), response.NumberOfInstances) |
| 1335 | assert.Nil(t, response.MeResults) |
| 1336 | |
| 1337 | // Verify string output for message |
| 1338 | packetString := packet.String() |
| 1339 | assert.NotZero(t, len(packetString)) |
| 1340 | } |
| 1341 | |
| 1342 | func TestEndSoftwareDownloadResponseSerialize(t *testing.T) { |
| 1343 | goodMessage := "8456350a00070000010000000000000000000000000000000000000000000000000000000000000000000028" |
| 1344 | |
| 1345 | omciLayer := &OMCI{ |
| 1346 | TransactionID: 0x8456, |
| 1347 | MessageType: EndSoftwareDownloadResponseType, |
| 1348 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1349 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1350 | } |
| 1351 | request := &EndSoftwareDownloadResponse{ |
| 1352 | MeBasePacket: MeBasePacket{ |
| 1353 | EntityClass: me.SoftwareImageClassID, |
| 1354 | // Default is zero |
| 1355 | }, |
| 1356 | Result: me.ProcessingError, |
| 1357 | NumberOfInstances: 0, |
| 1358 | } |
| 1359 | // Test serialization back to former string |
| 1360 | var options gopacket.SerializeOptions |
| 1361 | options.FixLengths = true |
| 1362 | |
| 1363 | buffer := gopacket.NewSerializeBuffer() |
| 1364 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1365 | assert.NoError(t, err) |
| 1366 | |
| 1367 | outgoingPacket := buffer.Bytes() |
| 1368 | reconstituted := packetToString(outgoingPacket) |
| 1369 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1370 | } |
| 1371 | |
| 1372 | func TestEndSoftwareDownloadResponseZeroTICSerialize(t *testing.T) { |
| 1373 | omciLayer := &OMCI{ |
| 1374 | TransactionID: 0x0, |
| 1375 | MessageType: EndSoftwareDownloadResponseType, |
| 1376 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1377 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1378 | } |
| 1379 | request := &EndSoftwareDownloadResponse{ |
| 1380 | MeBasePacket: MeBasePacket{ |
| 1381 | EntityClass: me.SoftwareImageClassID, |
| 1382 | // Default is zero |
| 1383 | }, |
| 1384 | Result: me.ProcessingError, |
| 1385 | NumberOfInstances: 0, |
| 1386 | } |
| 1387 | // Test serialization back to former string |
| 1388 | var options gopacket.SerializeOptions |
| 1389 | options.FixLengths = true |
| 1390 | |
| 1391 | buffer := gopacket.NewSerializeBuffer() |
| 1392 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1393 | assert.Error(t, err) |
| 1394 | } |
| 1395 | |
| 1396 | func TestEndSoftwareDownloadResponseSerializeExtended(t *testing.T) { |
| 1397 | goodMessage := "8456350b0007000100020100" |
| 1398 | |
| 1399 | omciLayer := &OMCI{ |
| 1400 | TransactionID: 0x8456, |
| 1401 | MessageType: EndSoftwareDownloadResponseType, |
| 1402 | DeviceIdentifier: ExtendedIdent, |
| 1403 | } |
| 1404 | request := &EndSoftwareDownloadResponse{ |
| 1405 | MeBasePacket: MeBasePacket{ |
| 1406 | EntityClass: me.SoftwareImageClassID, |
| 1407 | EntityInstance: 1, |
| 1408 | // Default is zero |
| 1409 | Extended: true, |
| 1410 | }, |
| 1411 | Result: me.ProcessingError, |
| 1412 | NumberOfInstances: 0, |
| 1413 | } |
| 1414 | // Test serialization back to former string |
| 1415 | var options gopacket.SerializeOptions |
| 1416 | options.FixLengths = true |
| 1417 | |
| 1418 | buffer := gopacket.NewSerializeBuffer() |
| 1419 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1420 | assert.NoError(t, err) |
| 1421 | |
| 1422 | outgoingPacket := buffer.Bytes() |
| 1423 | reconstituted := packetToString(outgoingPacket) |
| 1424 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1425 | } |
| 1426 | |
| 1427 | func TestActivateSoftwareRequestDecode(t *testing.T) { |
| 1428 | goodMessage := "0009560a00070001020000000000000000000000000000000000000000000000000000000000000000000028" |
| 1429 | data, err := stringToPacket(goodMessage) |
| 1430 | assert.NoError(t, err) |
| 1431 | |
| 1432 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1433 | assert.NotNil(t, packet) |
| 1434 | |
| 1435 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1436 | assert.NotNil(t, omciLayer) |
| 1437 | |
| 1438 | omciMsg, ok := omciLayer.(*OMCI) |
| 1439 | assert.True(t, ok) |
| 1440 | assert.Equal(t, uint16(9), omciMsg.TransactionID) |
| 1441 | assert.Equal(t, ActivateSoftwareRequestType, omciMsg.MessageType) |
| 1442 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1443 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1444 | |
| 1445 | msgLayer := packet.Layer(LayerTypeActivateSoftwareRequest) |
| 1446 | assert.NotNil(t, msgLayer) |
| 1447 | |
| 1448 | request, ok2 := msgLayer.(*ActivateSoftwareRequest) |
| 1449 | assert.True(t, ok2) |
| 1450 | assert.NotNil(t, request) |
| 1451 | assert.Equal(t, uint8(2), request.ActivateFlags) |
| 1452 | |
| 1453 | // Verify string output for message |
| 1454 | packetString := packet.String() |
| 1455 | assert.NotZero(t, len(packetString)) |
| 1456 | } |
| 1457 | |
| 1458 | func TestActivateSoftwareRequestDecodeExtended(t *testing.T) { |
| 1459 | goodMessage := "0009560b00070001000102" |
| 1460 | data, err := stringToPacket(goodMessage) |
| 1461 | assert.NoError(t, err) |
| 1462 | |
| 1463 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1464 | assert.NotNil(t, packet) |
| 1465 | |
| 1466 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1467 | assert.NotNil(t, omciLayer) |
| 1468 | |
| 1469 | omciMsg, ok := omciLayer.(*OMCI) |
| 1470 | assert.True(t, ok) |
| 1471 | assert.Equal(t, uint16(9), omciMsg.TransactionID) |
| 1472 | assert.Equal(t, ActivateSoftwareRequestType, omciMsg.MessageType) |
| 1473 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 1474 | assert.Equal(t, uint16(1), omciMsg.Length) |
| 1475 | |
| 1476 | msgLayer := packet.Layer(LayerTypeActivateSoftwareRequest) |
| 1477 | assert.NotNil(t, msgLayer) |
| 1478 | |
| 1479 | request, ok2 := msgLayer.(*ActivateSoftwareRequest) |
| 1480 | assert.True(t, ok2) |
| 1481 | assert.NotNil(t, request) |
| 1482 | assert.Equal(t, uint8(2), request.ActivateFlags) |
| 1483 | |
| 1484 | // Verify string output for message |
| 1485 | packetString := packet.String() |
| 1486 | assert.NotZero(t, len(packetString)) |
| 1487 | } |
| 1488 | |
| 1489 | func TestActivateSoftwareRequestSerialize(t *testing.T) { |
| 1490 | goodMessage := "0009560b00070001000102" |
| 1491 | |
| 1492 | omciLayer := &OMCI{ |
| 1493 | TransactionID: 0x09, |
| 1494 | MessageType: ActivateSoftwareRequestType, |
| 1495 | DeviceIdentifier: ExtendedIdent, |
| 1496 | } |
| 1497 | request := &ActivateSoftwareRequest{ |
| 1498 | MeBasePacket: MeBasePacket{ |
| 1499 | EntityClass: me.SoftwareImageClassID, |
| 1500 | EntityInstance: 1, |
| 1501 | Extended: true, |
| 1502 | }, |
| 1503 | ActivateFlags: 2, |
| 1504 | } |
| 1505 | // Test serialization back to former string |
| 1506 | var options gopacket.SerializeOptions |
| 1507 | options.FixLengths = true |
| 1508 | |
| 1509 | buffer := gopacket.NewSerializeBuffer() |
| 1510 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1511 | assert.NoError(t, err) |
| 1512 | |
| 1513 | outgoingPacket := buffer.Bytes() |
| 1514 | reconstituted := packetToString(outgoingPacket) |
| 1515 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1516 | } |
| 1517 | |
| 1518 | func TestActivateSoftwareRequestZeroTICSerialize(t *testing.T) { |
| 1519 | omciLayer := &OMCI{ |
| 1520 | TransactionID: 0x0, |
| 1521 | MessageType: ActivateSoftwareRequestType, |
| 1522 | DeviceIdentifier: ExtendedIdent, |
| 1523 | } |
| 1524 | request := &ActivateSoftwareRequest{ |
| 1525 | MeBasePacket: MeBasePacket{ |
| 1526 | EntityClass: me.SoftwareImageClassID, |
| 1527 | EntityInstance: 1, |
| 1528 | Extended: true, |
| 1529 | }, |
| 1530 | ActivateFlags: 2, |
| 1531 | } |
| 1532 | // Test serialization back to former string |
| 1533 | var options gopacket.SerializeOptions |
| 1534 | options.FixLengths = true |
| 1535 | |
| 1536 | buffer := gopacket.NewSerializeBuffer() |
| 1537 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1538 | assert.Error(t, err) |
| 1539 | } |
| 1540 | |
| 1541 | func TestActivateSoftwareRequestSerializeExtended(t *testing.T) { |
| 1542 | goodMessage := "0009560b00070001000102" |
| 1543 | |
| 1544 | omciLayer := &OMCI{ |
| 1545 | TransactionID: 0x09, |
| 1546 | MessageType: ActivateSoftwareRequestType, |
| 1547 | DeviceIdentifier: ExtendedIdent, |
| 1548 | } |
| 1549 | request := &ActivateSoftwareRequest{ |
| 1550 | MeBasePacket: MeBasePacket{ |
| 1551 | EntityClass: me.SoftwareImageClassID, |
| 1552 | EntityInstance: 1, |
| 1553 | Extended: true, |
| 1554 | }, |
| 1555 | ActivateFlags: 2, |
| 1556 | } |
| 1557 | // Test serialization back to former string |
| 1558 | var options gopacket.SerializeOptions |
| 1559 | options.FixLengths = true |
| 1560 | |
| 1561 | buffer := gopacket.NewSerializeBuffer() |
| 1562 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1563 | assert.NoError(t, err) |
| 1564 | |
| 1565 | outgoingPacket := buffer.Bytes() |
| 1566 | reconstituted := packetToString(outgoingPacket) |
| 1567 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1568 | } |
| 1569 | |
| 1570 | func TestActivateSoftwareResponseDecode(t *testing.T) { |
| 1571 | goodMessage := "0009360a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 1572 | data, err := stringToPacket(goodMessage) |
| 1573 | assert.NoError(t, err) |
| 1574 | |
| 1575 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1576 | assert.NotNil(t, packet) |
| 1577 | |
| 1578 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1579 | assert.NotNil(t, omciLayer) |
| 1580 | |
| 1581 | omciMsg, ok := omciLayer.(*OMCI) |
| 1582 | assert.True(t, ok) |
| 1583 | assert.Equal(t, omciMsg.TransactionID, uint16(9)) |
| 1584 | assert.Equal(t, omciMsg.MessageType, ActivateSoftwareResponseType) |
| 1585 | assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent) |
| 1586 | assert.Equal(t, omciMsg.Length, uint16(40)) |
| 1587 | |
| 1588 | msgLayer := packet.Layer(LayerTypeActivateSoftwareResponse) |
| 1589 | |
| 1590 | assert.NotNil(t, msgLayer) |
| 1591 | |
| 1592 | response, ok2 := msgLayer.(*ActivateSoftwareResponse) |
| 1593 | assert.True(t, ok2) |
| 1594 | assert.NotNil(t, response) |
| 1595 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 1596 | |
| 1597 | // Verify string output for message |
| 1598 | packetString := packet.String() |
| 1599 | assert.NotZero(t, len(packetString)) |
| 1600 | } |
| 1601 | |
| 1602 | func TestActivateSoftwareResponseDecodeExtended(t *testing.T) { |
| 1603 | goodMessage := "0009360b00070001000106" |
| 1604 | data, err := stringToPacket(goodMessage) |
| 1605 | assert.NoError(t, err) |
| 1606 | |
| 1607 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1608 | assert.NotNil(t, packet) |
| 1609 | |
| 1610 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1611 | assert.NotNil(t, omciLayer) |
| 1612 | |
| 1613 | omciMsg, ok := omciLayer.(*OMCI) |
| 1614 | assert.True(t, ok) |
| 1615 | assert.Equal(t, uint16(9), omciMsg.TransactionID) |
| 1616 | assert.Equal(t, ActivateSoftwareResponseType, omciMsg.MessageType) |
| 1617 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 1618 | assert.Equal(t, uint16(1), omciMsg.Length) |
| 1619 | |
| 1620 | msgLayer := packet.Layer(LayerTypeActivateSoftwareResponse) |
| 1621 | assert.NotNil(t, msgLayer) |
| 1622 | |
| 1623 | response, ok2 := msgLayer.(*ActivateSoftwareResponse) |
| 1624 | assert.True(t, ok2) |
| 1625 | assert.NotNil(t, response) |
| 1626 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 1627 | |
| 1628 | // Verify string output for message |
| 1629 | packetString := packet.String() |
| 1630 | assert.NotZero(t, len(packetString)) |
| 1631 | } |
| 1632 | |
| 1633 | func TestActivateSoftwareResponseSerialize(t *testing.T) { |
| 1634 | goodMessage := "0009360a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 1635 | |
| 1636 | omciLayer := &OMCI{ |
| 1637 | TransactionID: 0x09, |
| 1638 | MessageType: ActivateSoftwareResponseType, |
| 1639 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1640 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1641 | } |
| 1642 | request := &ActivateSoftwareResponse{ |
| 1643 | MeBasePacket: MeBasePacket{ |
| 1644 | EntityClass: me.SoftwareImageClassID, |
| 1645 | EntityInstance: 1, |
| 1646 | }, |
| 1647 | Result: me.DeviceBusy, |
| 1648 | } |
| 1649 | // Test serialization back to former string |
| 1650 | var options gopacket.SerializeOptions |
| 1651 | options.FixLengths = true |
| 1652 | |
| 1653 | buffer := gopacket.NewSerializeBuffer() |
| 1654 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1655 | assert.NoError(t, err) |
| 1656 | |
| 1657 | outgoingPacket := buffer.Bytes() |
| 1658 | reconstituted := packetToString(outgoingPacket) |
| 1659 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1660 | } |
| 1661 | |
| 1662 | func TestActivateSoftwareResponseZeroTICSerialize(t *testing.T) { |
| 1663 | omciLayer := &OMCI{ |
| 1664 | TransactionID: 0x0, |
| 1665 | MessageType: ActivateSoftwareResponseType, |
| 1666 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1667 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1668 | } |
| 1669 | request := &ActivateSoftwareResponse{ |
| 1670 | MeBasePacket: MeBasePacket{ |
| 1671 | EntityClass: me.SoftwareImageClassID, |
| 1672 | EntityInstance: 1, |
| 1673 | }, |
| 1674 | Result: me.DeviceBusy, |
| 1675 | } |
| 1676 | // Test serialization back to former string |
| 1677 | var options gopacket.SerializeOptions |
| 1678 | options.FixLengths = true |
| 1679 | |
| 1680 | buffer := gopacket.NewSerializeBuffer() |
| 1681 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1682 | assert.Error(t, err) |
| 1683 | } |
| 1684 | |
| 1685 | func TestActivateSoftwareResponseSerializeExtended(t *testing.T) { |
| 1686 | goodMessage := "0009360b00070001000106" |
| 1687 | |
| 1688 | omciLayer := &OMCI{ |
| 1689 | TransactionID: 0x09, |
| 1690 | MessageType: ActivateSoftwareResponseType, |
| 1691 | DeviceIdentifier: ExtendedIdent, |
| 1692 | } |
| 1693 | request := &ActivateSoftwareResponse{ |
| 1694 | MeBasePacket: MeBasePacket{ |
| 1695 | EntityClass: me.SoftwareImageClassID, |
| 1696 | EntityInstance: 1, |
| 1697 | Extended: true, |
| 1698 | }, |
| 1699 | Result: me.DeviceBusy, |
| 1700 | } |
| 1701 | // Test serialization back to former string |
| 1702 | var options gopacket.SerializeOptions |
| 1703 | options.FixLengths = true |
| 1704 | |
| 1705 | buffer := gopacket.NewSerializeBuffer() |
| 1706 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1707 | assert.NoError(t, err) |
| 1708 | |
| 1709 | outgoingPacket := buffer.Bytes() |
| 1710 | reconstituted := packetToString(outgoingPacket) |
| 1711 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1712 | } |
| 1713 | |
| 1714 | func TestCommitSoftwareRequestDecode(t *testing.T) { |
| 1715 | goodMessage := "0011570a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1716 | data, err := stringToPacket(goodMessage) |
| 1717 | assert.NoError(t, err) |
| 1718 | |
| 1719 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1720 | assert.NotNil(t, packet) |
| 1721 | |
| 1722 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1723 | assert.NotNil(t, omciLayer) |
| 1724 | |
| 1725 | omciMsg, ok := omciLayer.(*OMCI) |
| 1726 | assert.True(t, ok) |
| 1727 | assert.NotNil(t, omciMsg) |
| 1728 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 1729 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 1730 | assert.Equal(t, LayerTypeCommitSoftwareRequest, omciMsg.NextLayerType()) |
| 1731 | assert.Equal(t, uint16(0x11), omciMsg.TransactionID) |
| 1732 | assert.Equal(t, CommitSoftwareRequestType, omciMsg.MessageType) |
| 1733 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1734 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1735 | |
| 1736 | msgLayer := packet.Layer(LayerTypeCommitSoftwareRequest) |
| 1737 | assert.NotNil(t, msgLayer) |
| 1738 | |
| 1739 | request, ok2 := msgLayer.(*CommitSoftwareRequest) |
| 1740 | assert.True(t, ok2) |
| 1741 | assert.NotNil(t, request) |
| 1742 | assert.Equal(t, LayerTypeCommitSoftwareRequest, request.LayerType()) |
| 1743 | assert.Equal(t, LayerTypeCommitSoftwareRequest, request.CanDecode()) |
| 1744 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 1745 | assert.Equal(t, uint16(1), request.MeBasePacket.EntityInstance) |
| 1746 | |
| 1747 | // Verify string output for message |
| 1748 | packetString := packet.String() |
| 1749 | assert.NotZero(t, len(packetString)) |
| 1750 | } |
| 1751 | |
| 1752 | func TestCommitSoftwareRequestDecodeExtended(t *testing.T) { |
| 1753 | goodMessage := "0011570b000700010000" |
| 1754 | data, err := stringToPacket(goodMessage) |
| 1755 | assert.NoError(t, err) |
| 1756 | |
| 1757 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1758 | assert.NotNil(t, packet) |
| 1759 | |
| 1760 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1761 | assert.NotNil(t, omciLayer) |
| 1762 | |
| 1763 | omciMsg, ok := omciLayer.(*OMCI) |
| 1764 | assert.True(t, ok) |
| 1765 | assert.NotNil(t, omciMsg) |
| 1766 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 1767 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 1768 | assert.Equal(t, LayerTypeCommitSoftwareRequest, omciMsg.NextLayerType()) |
| 1769 | assert.Equal(t, uint16(0x11), omciMsg.TransactionID) |
| 1770 | assert.Equal(t, CommitSoftwareRequestType, omciMsg.MessageType) |
| 1771 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 1772 | assert.Equal(t, uint16(0), omciMsg.Length) |
| 1773 | |
| 1774 | msgLayer := packet.Layer(LayerTypeCommitSoftwareRequest) |
| 1775 | assert.NotNil(t, msgLayer) |
| 1776 | |
| 1777 | request, ok2 := msgLayer.(*CommitSoftwareRequest) |
| 1778 | assert.True(t, ok2) |
| 1779 | assert.NotNil(t, request) |
| 1780 | assert.Equal(t, LayerTypeCommitSoftwareRequest, request.LayerType()) |
| 1781 | assert.Equal(t, LayerTypeCommitSoftwareRequest, request.CanDecode()) |
| 1782 | assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType()) |
| 1783 | assert.Equal(t, uint16(1), request.MeBasePacket.EntityInstance) |
| 1784 | |
| 1785 | // Verify string output for message |
| 1786 | packetString := packet.String() |
| 1787 | assert.NotZero(t, len(packetString)) |
| 1788 | } |
| 1789 | |
| 1790 | func TestCommitSoftwareRequestSerialize(t *testing.T) { |
| 1791 | goodMessage := "0044570a00070001000000000000000000000000000000000000000000000000000000000000000000000028" |
| 1792 | |
| 1793 | omciLayer := &OMCI{ |
| 1794 | TransactionID: 0x44, |
| 1795 | MessageType: CommitSoftwareRequestType, |
| 1796 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1797 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1798 | } |
| 1799 | request := &CommitSoftwareRequest{ |
| 1800 | MeBasePacket: MeBasePacket{ |
| 1801 | EntityClass: me.SoftwareImageClassID, |
| 1802 | EntityInstance: 1, // Default Instance ID is 0 |
| 1803 | }, |
| 1804 | } |
| 1805 | // Test serialization back to former string |
| 1806 | var options gopacket.SerializeOptions |
| 1807 | options.FixLengths = true |
| 1808 | |
| 1809 | buffer := gopacket.NewSerializeBuffer() |
| 1810 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1811 | assert.NoError(t, err) |
| 1812 | |
| 1813 | outgoingPacket := buffer.Bytes() |
| 1814 | reconstituted := packetToString(outgoingPacket) |
| 1815 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1816 | } |
| 1817 | |
| 1818 | func TestCommitSoftwareRequestZeroTICSerialize(t *testing.T) { |
| 1819 | omciLayer := &OMCI{ |
| 1820 | TransactionID: 0x0, |
| 1821 | MessageType: CommitSoftwareRequestType, |
| 1822 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1823 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1824 | } |
| 1825 | request := &CommitSoftwareRequest{ |
| 1826 | MeBasePacket: MeBasePacket{ |
| 1827 | EntityClass: me.SoftwareImageClassID, |
| 1828 | EntityInstance: 1, // Default Instance ID is 0 |
| 1829 | }, |
| 1830 | } |
| 1831 | // Test serialization back to former string |
| 1832 | var options gopacket.SerializeOptions |
| 1833 | options.FixLengths = true |
| 1834 | |
| 1835 | buffer := gopacket.NewSerializeBuffer() |
| 1836 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1837 | assert.Error(t, err) |
| 1838 | } |
| 1839 | |
| 1840 | func TestCommitSoftwareRequestSerializeExtended(t *testing.T) { |
| 1841 | goodMessage := "0011570b000700010000" |
| 1842 | |
| 1843 | omciLayer := &OMCI{ |
| 1844 | TransactionID: 0x11, |
| 1845 | MessageType: CommitSoftwareRequestType, |
| 1846 | DeviceIdentifier: ExtendedIdent, |
| 1847 | } |
| 1848 | request := &CommitSoftwareRequest{ |
| 1849 | MeBasePacket: MeBasePacket{ |
| 1850 | EntityClass: me.SoftwareImageClassID, |
| 1851 | EntityInstance: 1, // Default Instance ID is 0 |
| 1852 | Extended: true, |
| 1853 | }, |
| 1854 | } |
| 1855 | // Test serialization back to former string |
| 1856 | var options gopacket.SerializeOptions |
| 1857 | options.FixLengths = true |
| 1858 | |
| 1859 | buffer := gopacket.NewSerializeBuffer() |
| 1860 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1861 | assert.NoError(t, err) |
| 1862 | |
| 1863 | outgoingPacket := buffer.Bytes() |
| 1864 | reconstituted := packetToString(outgoingPacket) |
| 1865 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1866 | } |
| 1867 | |
| 1868 | func TestCommitSoftwareResponseDecode(t *testing.T) { |
| 1869 | goodMessage := "00aa370a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 1870 | data, err := stringToPacket(goodMessage) |
| 1871 | assert.NoError(t, err) |
| 1872 | |
| 1873 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1874 | assert.NotNil(t, packet) |
| 1875 | |
| 1876 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1877 | assert.NotNil(t, omciLayer) |
| 1878 | |
| 1879 | omciMsg, ok := omciLayer.(*OMCI) |
| 1880 | assert.True(t, ok) |
| 1881 | assert.NotNil(t, omciMsg) |
| 1882 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 1883 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 1884 | assert.Equal(t, LayerTypeCommitSoftwareResponse, omciMsg.NextLayerType()) |
| 1885 | assert.Equal(t, uint16(0xaa), omciMsg.TransactionID) |
| 1886 | assert.Equal(t, CommitSoftwareResponseType, omciMsg.MessageType) |
| 1887 | assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier) |
| 1888 | assert.Equal(t, uint16(40), omciMsg.Length) |
| 1889 | |
| 1890 | msgLayer := packet.Layer(LayerTypeCommitSoftwareResponse) |
| 1891 | |
| 1892 | assert.NotNil(t, msgLayer) |
| 1893 | |
| 1894 | response, ok2 := msgLayer.(*CommitSoftwareResponse) |
| 1895 | assert.True(t, ok2) |
| 1896 | assert.NotNil(t, response) |
| 1897 | assert.Equal(t, LayerTypeCommitSoftwareResponse, response.LayerType()) |
| 1898 | assert.Equal(t, LayerTypeCommitSoftwareResponse, response.CanDecode()) |
| 1899 | assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType()) |
| 1900 | assert.Equal(t, uint16(1), response.MeBasePacket.EntityInstance) |
| 1901 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 1902 | |
| 1903 | // Verify string output for message |
| 1904 | packetString := packet.String() |
| 1905 | assert.NotZero(t, len(packetString)) |
| 1906 | } |
| 1907 | |
| 1908 | func TestCommitSoftwareResponseDecodeExtended(t *testing.T) { |
| 1909 | goodMessage := "00aa370b00070001000106" |
| 1910 | data, err := stringToPacket(goodMessage) |
| 1911 | assert.NoError(t, err) |
| 1912 | |
| 1913 | packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy) |
| 1914 | assert.NotNil(t, packet) |
| 1915 | |
| 1916 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1917 | assert.NotNil(t, omciLayer) |
| 1918 | |
| 1919 | omciMsg, ok := omciLayer.(*OMCI) |
| 1920 | assert.True(t, ok) |
| 1921 | assert.NotNil(t, omciMsg) |
| 1922 | assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType()) |
| 1923 | assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode()) |
| 1924 | assert.Equal(t, LayerTypeCommitSoftwareResponse, omciMsg.NextLayerType()) |
| 1925 | assert.Equal(t, uint16(0xaa), omciMsg.TransactionID) |
| 1926 | assert.Equal(t, CommitSoftwareResponseType, omciMsg.MessageType) |
| 1927 | assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier) |
| 1928 | assert.Equal(t, uint16(1), omciMsg.Length) |
| 1929 | |
| 1930 | msgLayer := packet.Layer(LayerTypeCommitSoftwareResponse) |
| 1931 | |
| 1932 | assert.NotNil(t, msgLayer) |
| 1933 | |
| 1934 | response, ok2 := msgLayer.(*CommitSoftwareResponse) |
| 1935 | assert.True(t, ok2) |
| 1936 | assert.NotNil(t, response) |
| 1937 | assert.Equal(t, LayerTypeCommitSoftwareResponse, response.LayerType()) |
| 1938 | assert.Equal(t, LayerTypeCommitSoftwareResponse, response.CanDecode()) |
| 1939 | assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType()) |
| 1940 | assert.Equal(t, uint16(1), response.MeBasePacket.EntityInstance) |
| 1941 | assert.Equal(t, me.DeviceBusy, response.Result) |
| 1942 | |
| 1943 | // Verify string output for message |
| 1944 | packetString := packet.String() |
| 1945 | assert.NotZero(t, len(packetString)) |
| 1946 | } |
| 1947 | |
| 1948 | func TestCommitSoftwareResponseSerialize(t *testing.T) { |
| 1949 | goodMessage := "8001370a00070001060000000000000000000000000000000000000000000000000000000000000000000028" |
| 1950 | |
| 1951 | omciLayer := &OMCI{ |
| 1952 | TransactionID: 0x8001, |
| 1953 | MessageType: CommitSoftwareResponseType, |
| 1954 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1955 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1956 | } |
| 1957 | request := &CommitSoftwareResponse{ |
| 1958 | MeBasePacket: MeBasePacket{ |
| 1959 | EntityClass: me.SoftwareImageClassID, |
| 1960 | EntityInstance: 1, // Default Instance ID is 0 |
| 1961 | }, |
| 1962 | Result: me.DeviceBusy, |
| 1963 | } |
| 1964 | // Test serialization back to former string |
| 1965 | var options gopacket.SerializeOptions |
| 1966 | options.FixLengths = true |
| 1967 | |
| 1968 | buffer := gopacket.NewSerializeBuffer() |
| 1969 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1970 | assert.NoError(t, err) |
| 1971 | |
| 1972 | outgoingPacket := buffer.Bytes() |
| 1973 | reconstituted := packetToString(outgoingPacket) |
| 1974 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 1975 | } |
| 1976 | |
| 1977 | func TestCommitSoftwareResponseZeroTICSerialize(t *testing.T) { |
| 1978 | omciLayer := &OMCI{ |
| 1979 | TransactionID: 0x0, |
| 1980 | MessageType: CommitSoftwareResponseType, |
| 1981 | // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline |
| 1982 | // Length: 0x28, // Optional, defaults to 40 octets |
| 1983 | } |
| 1984 | request := &CommitSoftwareResponse{ |
| 1985 | MeBasePacket: MeBasePacket{ |
| 1986 | EntityClass: me.SoftwareImageClassID, |
| 1987 | EntityInstance: 1, // Default Instance ID is 0 |
| 1988 | }, |
| 1989 | Result: me.DeviceBusy, |
| 1990 | } |
| 1991 | // Test serialization back to former string |
| 1992 | var options gopacket.SerializeOptions |
| 1993 | options.FixLengths = true |
| 1994 | |
| 1995 | buffer := gopacket.NewSerializeBuffer() |
| 1996 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 1997 | assert.Error(t, err) |
| 1998 | } |
| 1999 | |
| 2000 | func TestCommitSoftwareResponseSerializeExtended(t *testing.T) { |
| 2001 | goodMessage := "8001370b00070001000106" |
| 2002 | |
| 2003 | omciLayer := &OMCI{ |
| 2004 | TransactionID: 0x8001, |
| 2005 | MessageType: CommitSoftwareResponseType, |
| 2006 | DeviceIdentifier: ExtendedIdent, |
| 2007 | } |
| 2008 | request := &CommitSoftwareResponse{ |
| 2009 | MeBasePacket: MeBasePacket{ |
| 2010 | EntityClass: me.SoftwareImageClassID, |
| 2011 | EntityInstance: 1, // Default Instance ID is 0 |
| 2012 | Extended: true, |
| 2013 | }, |
| 2014 | Result: me.DeviceBusy, |
| 2015 | } |
| 2016 | // Test serialization back to former string |
| 2017 | var options gopacket.SerializeOptions |
| 2018 | options.FixLengths = true |
| 2019 | |
| 2020 | buffer := gopacket.NewSerializeBuffer() |
| 2021 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 2022 | assert.NoError(t, err) |
| 2023 | |
| 2024 | outgoingPacket := buffer.Bytes() |
| 2025 | reconstituted := packetToString(outgoingPacket) |
| 2026 | assert.Equal(t, strings.ToLower(goodMessage), reconstituted) |
| 2027 | } |