blob: 23e020c14d87eb633e21b96ccfb44ba11e657cc3 [file] [log] [blame]
Chip Boling6e27b352020-02-14 09:10:01 -06001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
Andrea Campanella7167ebb2020-02-24 09:56:38 +01003 * Copyright 2020-present Open Networking Foundation
4
Chip Boling6e27b352020-02-14 09:10:01 -06005 * 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 Campanella7167ebb2020-02-24 09:56:38 +01008
Chip Boling6e27b352020-02-14 09:10:01 -06009 * http://www.apache.org/licenses/LICENSE-2.0
Andrea Campanella7167ebb2020-02-24 09:56:38 +010010
Chip Boling6e27b352020-02-14 09:10:01 -060011 * 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 Boling6e27b352020-02-14 09:10:01 -060016 */
17package omci_test
18
19import (
20 "encoding/base64"
Chip Boling157c9b92021-04-21 09:58:36 -050021 "encoding/binary"
Chip Boling6e27b352020-02-14 09:10:01 -060022 "fmt"
Chip Boling34ebcb62021-02-02 12:13:58 -060023 "github.com/google/gopacket"
Andrea Campanella7167ebb2020-02-24 09:56:38 +010024 . "github.com/opencord/omci-lib-go"
25 me "github.com/opencord/omci-lib-go/generated"
Chip Boling6e27b352020-02-14 09:10:01 -060026 "github.com/stretchr/testify/assert"
27 "strings"
28 "testing"
29)
30
31var 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
56var 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 Boling157c9b92021-04-21 09:58:36 -0500103var allExtendedMessageTypes = [...]MessageType{
104 GetRequestType,
105 GetResponseType,
106}
107
Chip Boling6e27b352020-02-14 09:10:01 -0600108var 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
119func 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
131func 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
141func 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
150func 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
210func 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
263func 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 Bolingd8637b02021-04-29 08:36:38 -0500274 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600275
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
332func 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
370func 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 Bolingd8637b02021-04-29 08:36:38 -0500379 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600380
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
400func 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
430func 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 Bolingd8637b02021-04-29 08:36:38 -0500439 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600440
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
461func 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
489func 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 Bolingd8637b02021-04-29 08:36:38 -0500498 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600499
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
520func 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
549func 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 Bolingd8637b02021-04-29 08:36:38 -0500558 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600559
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
579func 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
609func 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 Bolingd8637b02021-04-29 08:36:38 -0500618 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600619
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
639func 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
669func TestSetResponseTableFailedAttributesDecode(t *testing.T) {
670 // This is a SET Response with failed and unsupported attributes
671 // TODO:Implement
672}
673
674func TestSetResponseTableFailedAttributesSerialize(t *testing.T) {
675 // This is a SET Response with failed and unsupported attributes
676 // TODO:Implement
677}
678
679func 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 Bolingd8637b02021-04-29 08:36:38 -0500688 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600689
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
709func 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
738func 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
772func 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
807func 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
815func 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
848func 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
906func TestGetResponseTableFailedAttributesDecode(t *testing.T) {
907 // This is a GET Response with failed and unsupported attributes
908 // TODO:Implement
909}
910
911func TestGetResponseTableFailedAttributesSerialize(t *testing.T) {
912 // This is a GET Response with failed and unsupported attributes
913 // TODO:Implement
914}
915
916func 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
922func 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
928func 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 Bolingd8637b02021-04-29 08:36:38 -0500937 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600938
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
959func 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
988func 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 Bolingd8637b02021-04-29 08:36:38 -0500997 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -0600998
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
1019func 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
1048func 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 Bolingd8637b02021-04-29 08:36:38 -05001058 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06001059
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
1079func 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
1108func 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 Bolingd8637b02021-04-29 08:36:38 -05001117 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06001118
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
1144func 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
1178func 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
1188func 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
1194func 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 Bolingd8637b02021-04-29 08:36:38 -05001203 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06001204
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
1224func 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
1255func 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 Bolingd8637b02021-04-29 08:36:38 -05001264 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06001265
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
1282func 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
1314func 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 Bolingd8637b02021-04-29 08:36:38 -05001323 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06001324
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
1345func 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
1374func 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 Bolingd8637b02021-04-29 08:36:38 -05001383 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06001384
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
1425func 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
1475func 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
1484func 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 Boling8c8018e2021-02-22 15:56:00 -06001492// 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 Boling6e27b352020-02-14 09:10:01 -06001501func TestStartSoftwareDownloadRequestDecode(t *testing.T) {
Chip Boling8c8018e2021-02-22 15:56:00 -06001502 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 Bolingd8637b02021-04-29 08:36:38 -05001510 assert.NotNil(t, omciLayer)
Chip Boling8c8018e2021-02-22 15:56:00 -06001511
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 Boling6e27b352020-02-14 09:10:01 -06001532}
1533
1534func 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
1563func 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 Bolingd8637b02021-04-29 08:36:38 -05001573 //assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06001574 //
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
1595func 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 Boling8c8018e2021-02-22 15:56:00 -06001624// 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
1631func 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 Bolingd8637b02021-04-29 08:36:38 -05001640 assert.NotNil(t, omciLayer)
Chip Boling8c8018e2021-02-22 15:56:00 -06001641
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 Boling00a30d22021-05-04 13:31:52 -05001657 assert.Equal(t, MaxDownloadSectionLength, len(request.SectionData))
Chip Boling8c8018e2021-02-22 15:56:00 -06001658
1659 sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031")
1660 assert.Nil(t, genErr)
1661 assert.NotNil(t, sectionData)
Chip Boling00a30d22021-05-04 13:31:52 -05001662 assert.Equal(t, MaxDownloadSectionLength, len(sectionData))
Chip Boling8c8018e2021-02-22 15:56:00 -06001663 assert.Equal(t, sectionData, request.SectionData[:])
1664
1665 // Verify string output for message
1666 packetString := packet.String()
1667 assert.NotZero(t, len(packetString))
Chip Boling6e27b352020-02-14 09:10:01 -06001668}
1669
Chip Boling8c8018e2021-02-22 15:56:00 -06001670func 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 Bolingd8637b02021-04-29 08:36:38 -05001679 assert.NotNil(t, omciLayer)
Chip Boling8c8018e2021-02-22 15:56:00 -06001680
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 Boling00a30d22021-05-04 13:31:52 -05001701 assert.Equal(t, MaxDownloadSectionLength, len(sectionData))
Chip Boling8c8018e2021-02-22 15:56:00 -06001702 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
1709func 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 Boling00a30d22021-05-04 13:31:52 -05001721 assert.Equal(t, MaxDownloadSectionLength, len(sectionData))
Chip Boling8c8018e2021-02-22 15:56:00 -06001722
1723 request := &DownloadSectionRequest{
1724 MeBasePacket: MeBasePacket{
1725 EntityClass: me.SoftwareImageClassID,
1726 // Default Instance ID is 0
1727 },
1728 SectionNumber: 0xcc,
Chip Boling00a30d22021-05-04 13:31:52 -05001729 SectionData: sectionData,
Chip Boling8c8018e2021-02-22 15:56:00 -06001730 }
Chip Boling00a30d22021-05-04 13:31:52 -05001731 // Test serialization back to former string
1732 var options gopacket.SerializeOptions
1733 options.FixLengths = true
Chip Boling8c8018e2021-02-22 15:56:00 -06001734
Chip Boling00a30d22021-05-04 13:31:52 -05001735 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
1744func 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 Boling8c8018e2021-02-22 15:56:00 -06001767 // 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
1780func TestDownloadSectionRequestSerializeResponseExpectedMethod1(t *testing.T) {
1781 goodMessage := "2468540a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028"
1782
1783 omciLayer := &OMCI{
Chip Boling2ccec852021-02-24 11:18:02 -06001784 TransactionID: 0x2468,
1785 MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType
Chip Boling8c8018e2021-02-22 15:56:00 -06001786 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 Boling00a30d22021-05-04 13:31:52 -05001793 assert.Equal(t, MaxDownloadSectionLength, len(sectionData))
Chip Boling8c8018e2021-02-22 15:56:00 -06001794
1795 request := &DownloadSectionRequest{
1796 MeBasePacket: MeBasePacket{
1797 EntityClass: me.SoftwareImageClassID,
1798 // Default Instance ID is 0
1799 },
1800 SectionNumber: 0xcc,
Chip Boling00a30d22021-05-04 13:31:52 -05001801 SectionData: sectionData,
Chip Boling8c8018e2021-02-22 15:56:00 -06001802 }
Chip Boling8c8018e2021-02-22 15:56:00 -06001803 // 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
1816func 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 Boling00a30d22021-05-04 13:31:52 -05001829 assert.Equal(t, MaxDownloadSectionLength, len(sectionData))
Chip Boling8c8018e2021-02-22 15:56:00 -06001830
1831 request := &DownloadSectionRequest{
1832 MeBasePacket: MeBasePacket{
Chip Boling2ccec852021-02-24 11:18:02 -06001833 EntityClass: me.SoftwareImageClassID,
1834 EntityInstance: 0x0001, // Default is zero, here we want image 1
Chip Boling8c8018e2021-02-22 15:56:00 -06001835 },
1836 SectionNumber: 0xcc,
Chip Boling00a30d22021-05-04 13:31:52 -05001837 SectionData: sectionData,
Chip Boling8c8018e2021-02-22 15:56:00 -06001838 }
Chip Boling8c8018e2021-02-22 15:56:00 -06001839 // 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 Boling6e27b352020-02-14 09:10:01 -06001850}
1851
1852func TestDownloadSectionResponseDecode(t *testing.T) {
Chip Boling588d9702021-02-26 09:48:07 -06001853 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 Bolingd8637b02021-04-29 08:36:38 -05001861 assert.NotNil(t, omciLayer)
Chip Boling588d9702021-02-26 09:48:07 -06001862
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 Boling6e27b352020-02-14 09:10:01 -06001883}
1884
1885func TestDownloadSectionResponseSerialize(t *testing.T) {
Chip Boling588d9702021-02-26 09:48:07 -06001886 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 Boling6e27b352020-02-14 09:10:01 -06001913}
1914
1915func TestEndSoftwareDownloadRequestDecode(t *testing.T) {
Chip Boling6e27b352020-02-14 09:10:01 -06001916 //
Chip Boling2ccec852021-02-24 11:18:02 -06001917 // 8100 55 0a 0007 0001 ff92a226 000f4240 01 0001 00000000000000000000000000000000000000000000000028
Chip Boling6e27b352020-02-14 09:10:01 -06001918 //
Chip Boling2ccec852021-02-24 11:18:02 -06001919 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 Bolingd8637b02021-04-29 08:36:38 -05001927 assert.NotNil(t, omciLayer)
Chip Boling2ccec852021-02-24 11:18:02 -06001928
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 Boling6e27b352020-02-14 09:10:01 -06001951}
1952
1953func TestEndSoftwareDownloadRequestSerialize(t *testing.T) {
Chip Boling2ccec852021-02-24 11:18:02 -06001954 // 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 Boling6e27b352020-02-14 09:10:01 -06001984}
1985
1986func TestEndSoftwareDownloadResponseDecode(t *testing.T) {
Chip Boling2ccec852021-02-24 11:18:02 -06001987 // 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 Bolingd8637b02021-04-29 08:36:38 -05001996 assert.NotNil(t, omciLayer)
Chip Boling2ccec852021-02-24 11:18:02 -06001997
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 Boling6e27b352020-02-14 09:10:01 -06002018}
2019
2020func TestEndSoftwareDownloadResponseSerialize(t *testing.T) {
Chip Boling2ccec852021-02-24 11:18:02 -06002021 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 Boling6e27b352020-02-14 09:10:01 -06002048}
2049
2050func 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 Bolingd8637b02021-04-29 08:36:38 -05002060 //assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002061 //
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
2081func 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
2110func 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 Bolingd8637b02021-04-29 08:36:38 -05002120 //assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002121 //
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
2142func 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
2171func TestCommitSoftwareRequestDecode(t *testing.T) {
Chip Boling58fc4d22021-03-10 13:23:53 -06002172 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 Bolingd8637b02021-04-29 08:36:38 -05002180 assert.NotNil(t, omciLayer)
Chip Boling58fc4d22021-03-10 13:23:53 -06002181
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 Boling6e27b352020-02-14 09:10:01 -06002200}
2201
2202func TestCommitSoftwareRequestSerialize(t *testing.T) {
Chip Boling58fc4d22021-03-10 13:23:53 -06002203 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 Boling6e27b352020-02-14 09:10:01 -06002228}
2229
2230func TestCommitSoftwareResponseDecode(t *testing.T) {
Chip Boling58fc4d22021-03-10 13:23:53 -06002231 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 Bolingd8637b02021-04-29 08:36:38 -05002239 assert.NotNil(t, omciLayer)
Chip Boling58fc4d22021-03-10 13:23:53 -06002240
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 Boling6e27b352020-02-14 09:10:01 -06002261}
2262
2263func TestCommitSoftwareResponseSerialize(t *testing.T) {
Chip Boling58fc4d22021-03-10 13:23:53 -06002264 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 Boling6e27b352020-02-14 09:10:01 -06002290}
2291
2292func 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 Bolingd8637b02021-04-29 08:36:38 -05002301 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002302
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
2321func 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
2349func 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 Bolingd8637b02021-04-29 08:36:38 -05002358 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002359
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
2384func 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
2418func 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 Bolingd8637b02021-04-29 08:36:38 -05002427 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002428
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
2447func 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
2477func 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 Bolingd8637b02021-04-29 08:36:38 -05002486 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002487
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
2510func 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
2539func 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 Bolingd8637b02021-04-29 08:36:38 -05002548 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002549
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
2572func 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
2601func 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 Bolingd8637b02021-04-29 08:36:38 -05002610 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002611
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
2635func 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
2665func 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 Bolingd8637b02021-04-29 08:36:38 -05002675 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002676
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
2709func 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
2743// TODO: Create request/response tests for all of the following types//GetCurrentData,
2744//SetTable}
2745
2746func TestAlarmNotificationDecode(t *testing.T) {
2747 goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028"
2748 data, err := stringToPacket(goodMessage)
2749 assert.NoError(t, err)
2750
2751 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2752 assert.NotNil(t, packet)
2753
2754 omciLayer := packet.Layer(LayerTypeOMCI)
Chip Bolingd8637b02021-04-29 08:36:38 -05002755 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002756
2757 omciMsg, ok := omciLayer.(*OMCI)
2758 assert.True(t, ok)
2759 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2760 assert.Equal(t, omciMsg.MessageType, AlarmNotificationType)
2761 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2762 assert.Equal(t, omciMsg.Length, uint16(40))
2763
2764 msgLayer := packet.Layer(LayerTypeAlarmNotification)
2765 assert.NotNil(t, msgLayer)
2766
2767 request, ok2 := msgLayer.(*AlarmNotificationMsg)
2768 assert.True(t, ok2)
2769 assert.NotNil(t, request)
2770 assert.Equal(t, request.EntityClass, me.PhysicalPathTerminationPointEthernetUniClassID)
2771 assert.Equal(t, request.EntityInstance, uint16(0x104))
2772 assert.Equal(t, request.AlarmBitmap, [28]byte{
2773 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2774 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2775 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2776 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2777 })
2778 assert.Equal(t, request.AlarmSequenceNumber, byte(5))
2779
Chip Boling34ebcb62021-02-02 12:13:58 -06002780 // Active/Clear tests
2781 active, err2 := request.IsAlarmActive(0)
2782 clear, err3 := request.IsAlarmClear(0)
2783 assert.Nil(t, err2)
2784 assert.Nil(t, err3)
2785 assert.True(t, active)
2786 assert.False(t, clear)
2787
2788 // Active/Clear for undefined alarm bits
2789 active, err2 = request.IsAlarmActive(1)
2790 clear, err3 = request.IsAlarmClear(1)
2791 assert.NotNil(t, err2)
2792 assert.NotNil(t, err3)
2793
Chip Boling6e27b352020-02-14 09:10:01 -06002794 // Verify string output for message
2795 packetString := packet.String()
2796 assert.NotZero(t, len(packetString))
2797}
2798
Chip Boling34ebcb62021-02-02 12:13:58 -06002799func TestInvalidClassAlarmNotificationDecode(t *testing.T) {
2800 // Choosing GalEthernetProfile (272) since it does not support alarms, show we should
2801 // file the decode
2802 badMessage := "0000100a01100104800000000000000000000000000000000000000000000000000000000000000500000028"
2803 data, err := stringToPacket(badMessage)
2804 assert.NoError(t, err)
2805
2806 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2807 assert.NotNil(t, packet)
2808
2809 omciLayer := packet.Layer(LayerTypeOMCI)
Chip Bolingd8637b02021-04-29 08:36:38 -05002810 assert.NotNil(t, omciLayer)
Chip Boling34ebcb62021-02-02 12:13:58 -06002811
2812 omciMsg, ok := omciLayer.(*OMCI)
2813 assert.True(t, ok)
2814 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2815 assert.Equal(t, omciMsg.MessageType, AlarmNotificationType)
2816 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2817 assert.Equal(t, omciMsg.Length, uint16(40))
2818
2819 msgLayer := packet.Layer(LayerTypeAlarmNotification)
2820 assert.Nil(t, msgLayer)
2821
2822 request, ok2 := msgLayer.(*AlarmNotificationMsg)
2823 assert.False(t, ok2)
2824 assert.Nil(t, request)
2825}
2826
2827func TestUnknownsMeAlarmNotificationDecode(t *testing.T) {
2828 // Choosing class ID 22 since it is in the G.988 class ID space and is reserved
2829 goodMessage := "0000100a00160104800000000000000000000000000000000000000000000000000000000000000500000028"
2830 data, err := stringToPacket(goodMessage)
2831 assert.NoError(t, err)
2832
2833 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2834 assert.NotNil(t, packet)
2835
2836 omciLayer := packet.Layer(LayerTypeOMCI)
Chip Bolingd8637b02021-04-29 08:36:38 -05002837 assert.NotNil(t, omciLayer)
Chip Boling34ebcb62021-02-02 12:13:58 -06002838
2839 omciMsg, ok := omciLayer.(*OMCI)
2840 assert.True(t, ok)
2841 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2842 assert.Equal(t, omciMsg.MessageType, AlarmNotificationType)
2843 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2844 assert.Equal(t, omciMsg.Length, uint16(40))
2845
2846 msgLayer := packet.Layer(LayerTypeAlarmNotification)
2847 assert.NotNil(t, msgLayer)
2848
2849 request, ok2 := msgLayer.(*AlarmNotificationMsg)
2850 assert.True(t, ok2)
2851 assert.NotNil(t, request)
2852 assert.Equal(t, request.EntityClass, me.ClassID(22))
2853 assert.Equal(t, request.EntityInstance, uint16(0x104))
2854 assert.Equal(t, request.AlarmBitmap, [28]byte{
2855 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2856 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2857 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2858 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2859 })
2860 assert.Equal(t, request.AlarmSequenceNumber, byte(5))
2861}
2862
2863func TestVendorSpecificAlarmNotificationDecode(t *testing.T) {
2864 // Choosing class ID 255 since it is in the first vendor specific class ID space
2865 goodMessage := "0000100a00FF0104800000000000000000000000000000000000000000000000000000000000000500000028"
2866 data, err := stringToPacket(goodMessage)
2867 assert.NoError(t, err)
2868
2869 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2870 assert.NotNil(t, packet)
2871
2872 omciLayer := packet.Layer(LayerTypeOMCI)
Chip Bolingd8637b02021-04-29 08:36:38 -05002873 assert.NotNil(t, omciLayer)
Chip Boling34ebcb62021-02-02 12:13:58 -06002874
2875 omciMsg, ok := omciLayer.(*OMCI)
2876 assert.True(t, ok)
2877 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2878 assert.Equal(t, omciMsg.MessageType, AlarmNotificationType)
2879 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2880 assert.Equal(t, omciMsg.Length, uint16(40))
2881
2882 msgLayer := packet.Layer(LayerTypeAlarmNotification)
2883 assert.NotNil(t, msgLayer)
2884
2885 request, ok2 := msgLayer.(*AlarmNotificationMsg)
2886 assert.True(t, ok2)
2887 assert.NotNil(t, request)
2888 assert.Equal(t, request.EntityClass, me.ClassID(255))
2889 assert.Equal(t, request.EntityInstance, uint16(0x104))
2890 assert.Equal(t, request.AlarmBitmap, [28]byte{
2891 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2892 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2893 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2894 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2895 })
2896 assert.Equal(t, request.AlarmSequenceNumber, byte(5))
2897}
2898
Chip Boling6e27b352020-02-14 09:10:01 -06002899func TestAlarmNotificationSerialize(t *testing.T) {
2900 goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028"
2901
2902 omciLayer := &OMCI{
2903 TransactionID: 0,
2904 MessageType: AlarmNotificationType,
2905 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2906 // Length: 0x28, // Optional, defaults to 40 octets
2907 }
2908 request := &AlarmNotificationMsg{
2909 MeBasePacket: MeBasePacket{
2910 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
2911 EntityInstance: uint16(0x104),
2912 },
2913 AlarmBitmap: [28]byte{
2914 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2915 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2916 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2917 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2918 },
2919 AlarmSequenceNumber: byte(5),
2920 }
2921 // Test serialization back to former string
2922 var options gopacket.SerializeOptions
2923 options.FixLengths = true
2924
2925 buffer := gopacket.NewSerializeBuffer()
2926 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2927 assert.NoError(t, err)
2928
2929 outgoingPacket := buffer.Bytes()
2930 reconstituted := packetToString(outgoingPacket)
2931 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2932}
2933
2934func TestAttributeValueChangeDecode(t *testing.T) {
2935 goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028"
2936 data, err := stringToPacket(goodMessage)
2937 assert.NoError(t, err)
2938
2939 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2940 assert.NotNil(t, packet)
2941
2942 omciLayer := packet.Layer(LayerTypeOMCI)
Chip Bolingd8637b02021-04-29 08:36:38 -05002943 assert.NotNil(t, omciLayer)
Chip Boling6e27b352020-02-14 09:10:01 -06002944
2945 omciMsg, ok := omciLayer.(*OMCI)
2946 assert.True(t, ok)
2947 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2948 assert.Equal(t, omciMsg.MessageType, AttributeValueChangeType)
2949 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2950 assert.Equal(t, omciMsg.Length, uint16(40))
2951
2952 msgLayer := packet.Layer(LayerTypeAttributeValueChange)
2953 assert.NotNil(t, msgLayer)
2954
2955 request, ok2 := msgLayer.(*AttributeValueChangeMsg)
2956 assert.True(t, ok2)
2957 assert.NotNil(t, request)
2958 assert.Equal(t, request.AttributeMask, uint16(0x8000))
2959 assert.Equal(t, request.EntityClass, me.SoftwareImageClassID)
2960 assert.Equal(t, request.EntityInstance, uint16(0))
2961 assert.Equal(t, request.Attributes["Version"], []byte{
2962 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36,
2963 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
2964
2965 // Verify string output for message
2966 packetString := packet.String()
2967 assert.NotZero(t, len(packetString))
2968}
2969
2970func TestAttributeValueChangeSerialize(t *testing.T) {
2971 goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028"
2972
2973 omciLayer := &OMCI{
2974 TransactionID: 0,
2975 MessageType: AttributeValueChangeType,
2976 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2977 // Length: 0x28, // Optional, defaults to 40 octets
2978 }
2979 request := &AttributeValueChangeMsg{
2980 MeBasePacket: MeBasePacket{
2981 EntityClass: me.SoftwareImageClassID,
2982 EntityInstance: uint16(0),
2983 },
2984 AttributeMask: uint16(0x8000),
2985 Attributes: me.AttributeValueMap{
2986 "Version": []byte{
2987 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36,
2988 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2989 },
2990 },
2991 }
2992 // Test serialization back to former string
2993 var options gopacket.SerializeOptions
2994 options.FixLengths = true
2995
2996 buffer := gopacket.NewSerializeBuffer()
2997 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2998 assert.NoError(t, err)
2999
3000 outgoingPacket := buffer.Bytes()
3001 reconstituted := packetToString(outgoingPacket)
3002 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3003}
3004
Chip Boling4e0ac9a2021-01-20 14:23:09 -06003005func TestJira3769(t *testing.T) {
3006 // VOL-3769. Error parsing get response with processing error and large mask
3007 sampleMessage := "035e290a0101000001FFFC000000000000000000000000000000000000000000000000000000000000000028"
3008 data, err := stringToPacket(sampleMessage)
3009 assert.NoError(t, err)
3010
3011 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3012 assert.NotNil(t, packet)
3013
3014 omciLayer := packet.Layer(LayerTypeOMCI)
3015 assert.NotNil(t, omciLayer)
3016
3017 omciMsg, ok := omciLayer.(*OMCI)
3018 assert.True(t, ok)
3019 assert.Equal(t, omciMsg.TransactionID, uint16(0x035e))
3020 assert.Equal(t, omciMsg.MessageType, GetResponseType)
3021 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
3022 assert.Equal(t, omciMsg.Length, uint16(40))
3023
3024 // before bugfix for this JIRA, the following call returned 'nil' Failure was
Chip Bolingd8637b02021-04-29 08:36:38 -05003025 // occurring before this at during getResponse decoding.
Chip Boling4e0ac9a2021-01-20 14:23:09 -06003026 msgLayer := packet.Layer(LayerTypeGetResponse)
3027 assert.NotNil(t, msgLayer)
3028
3029 response, ok2 := msgLayer.(*GetResponse)
3030 assert.True(t, ok2)
3031 assert.NotNil(t, response)
3032 assert.Equal(t, response.Result, me.ProcessingError)
3033 assert.Equal(t, response.AttributeMask, uint16(0xFFFC))
3034}
Chip Boling34ebcb62021-02-02 12:13:58 -06003035
Chip Boling2c046fa2021-02-23 11:30:29 -06003036func TestJira3863(t *testing.T) {
3037 goodMessage := "81a9240a013880010700000000000000000000000000000000000000000000000000000000000000000000283f73ddea"
3038 data, err := stringToPacket(goodMessage)
3039 assert.NoError(t, err)
3040
3041 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3042 assert.NotNil(t, packet)
3043
3044 omciLayer := packet.Layer(LayerTypeOMCI)
Chip Bolingd8637b02021-04-29 08:36:38 -05003045 assert.NotNil(t, omciLayer)
Chip Boling2c046fa2021-02-23 11:30:29 -06003046
3047 omciMsg, ok := omciLayer.(*OMCI)
3048 assert.True(t, ok)
3049 assert.NotNil(t, omciMsg)
3050
3051 msgLayer := packet.Layer(LayerTypeCreateResponse)
3052 assert.NotNil(t, msgLayer)
3053
3054 // FEC PM ME not in class map so the following was failing (ok2 false)
3055 response, ok2 := msgLayer.(*CreateResponse)
3056 assert.True(t, ok2)
3057 assert.NotNil(t, response)
3058
3059 // Verify string output for message
3060 packetString := packet.String()
3061 assert.NotZero(t, len(packetString))
3062}
Chip Boling157c9b92021-04-21 09:58:36 -05003063
3064func TestExtendedGetRequestDecode(t *testing.T) {
3065 //ONU-2G: 257
3066 goodMessage := "035e490b010100000002fffc"
3067 data, err := stringToPacket(goodMessage)
3068 assert.NoError(t, err)
3069
3070 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3071 assert.NotNil(t, packet)
3072
3073 omciLayer := packet.Layer(LayerTypeOMCI)
Chip Bolingd8637b02021-04-29 08:36:38 -05003074 assert.NotNil(t, omciLayer)
Chip Boling157c9b92021-04-21 09:58:36 -05003075
3076 omciMsg, ok := omciLayer.(*OMCI)
3077 assert.True(t, ok)
3078 assert.Equal(t, omciMsg.TransactionID, uint16(0x035e))
3079 assert.Equal(t, omciMsg.MessageType, GetRequestType)
3080 assert.Equal(t, omciMsg.DeviceIdentifier, ExtendedIdent)
3081 assert.Equal(t, omciMsg.Length, uint16(2))
3082
3083 msgLayer := packet.Layer(LayerTypeGetRequest)
3084 assert.NotNil(t, msgLayer)
3085
3086 request, ok2 := msgLayer.(*GetRequest)
3087 assert.True(t, ok2)
3088 assert.NotNil(t, request)
3089
3090 //ONU-2G: 257
3091 assert.Equal(t, me.Onu2GClassID, request.EntityClass)
3092 assert.Equal(t, uint16(0), request.EntityInstance)
3093 assert.Equal(t, uint16(0xfffc), request.AttributeMask)
3094
3095 // Verify string output for message
3096 packetString := packet.String()
3097 assert.NotZero(t, len(packetString))
3098}
3099
Chip Boling00a30d22021-05-04 13:31:52 -05003100func TestExtendedGetRequestDecodeTruncated(t *testing.T) {
3101 goodMessage := "035e490b010100000002ff"
3102 data, err := stringToPacket(goodMessage)
3103 assert.NoError(t, err)
3104
3105 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3106 assert.NotNil(t, packet)
3107
3108 failure := packet.ErrorLayer()
3109 assert.NotNil(t, failure)
3110
3111 decodeFailure, ok := failure.(*gopacket.DecodeFailure)
3112 assert.NotNil(t, decodeFailure)
3113 assert.True(t, ok)
3114 assert.NotNil(t, decodeFailure.String())
3115 assert.True(t, len(decodeFailure.String()) > 0)
3116
3117 metadata := packet.Metadata()
3118 assert.NotNil(t, metadata)
3119 assert.True(t, metadata.Truncated)
3120
3121 // Verify string output for message
3122 packetString := packet.String()
3123 assert.NotZero(t, len(packetString))
3124}
3125
Chip Boling157c9b92021-04-21 09:58:36 -05003126func TestExtendedGetRequestSerialize(t *testing.T) {
3127 goodMessage := "035e490b010100000002fffc"
3128
3129 omciLayer := &OMCI{
3130 TransactionID: 0x035e,
3131 MessageType: GetRequestType,
3132 DeviceIdentifier: ExtendedIdent,
3133 // Length parameter is optional for Extended message format serialization
3134 // and if present it will be overwritten during the serialization with the
3135 // actual value.
3136 }
3137 request := &GetRequest{
3138 MeBasePacket: MeBasePacket{
3139 EntityClass: me.Onu2GClassID,
3140 EntityInstance: uint16(0),
3141 Extended: true,
3142 },
3143 AttributeMask: uint16(0xfffc),
3144 }
3145 // Test serialization back to former string
3146 var options gopacket.SerializeOptions
3147 options.FixLengths = true
3148
3149 buffer := gopacket.NewSerializeBuffer()
3150 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3151 assert.NoError(t, err)
3152
3153 outgoingPacket := buffer.Bytes()
3154 reconstituted := packetToString(outgoingPacket)
3155 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3156}
3157
3158func TestExtendedGetResponseDecode(t *testing.T) {
3159 attrDef, omciErr := me.GetAttributesDefinitions(me.Onu2GClassID)
3160 assert.NotNil(t, attrDef)
3161 assert.NotNil(t, omciErr)
3162 assert.Equal(t, omciErr.StatusCode(), me.Success)
3163
3164 attributes := []interface{}{
3165 toOctets("AAAAAAAAAAAAAAAAAAAAAAAAAAA="), // 1: MultiByteField - "EquipmentId" (20 zeros)
3166 byte(0xb4), // 2: ByteField - "OpticalNetworkUnitManagementAndControlChannelOmccVersion"
3167 uint16(0x1234), // 3: Uint16Field - "VendorProductCode"
3168 byte(1), // 4: ByteField - "SecurityCapability"
3169 byte(1), // 5: ByteField - "SecurityMode"
3170 uint16(0x5678), // 6: Uint16Field - "TotalPriorityQueueNumber"
3171 byte(0x44), // 7: ByteField - "TotalTrafficSchedulerNumber"
3172 byte(1), // 8: ByteField - "Deprecated"
3173 uint16(0x55aa), // 9: Uint16Field - "TotalGemPortIdNumber"
3174 uint32(0xC4108011), // 10: Uint32Field - "Sysuptime"
3175 uint16(0x6), // 11: Uint16Field - "ConnectivityCapability"
3176 byte(6), // 12: ByteField - "CurrentConnectivityMode"
3177 uint16(2), // 13: Uint16Field - "QualityOfServiceQosConfigurationFlexibility"
3178 uint16(0x1234), // 14: Uint16Field - "PriorityQueueScaleFactor"
3179 }
3180 attributeData := make([]byte, 0)
3181
3182 // Walk through all attributes and encode them
3183 for _, value := range attributes {
3184 //attrDef, err := meDef.GetAttributeByIndex(index)
3185 var buf []byte
3186 u8, ok := value.(byte)
3187 if ok {
3188 buf = []byte{u8}
3189 } else {
3190 u16, ok := value.(uint16)
3191 if ok {
3192 buf = make([]byte, 2)
3193 binary.BigEndian.PutUint16(buf, u16)
3194 } else {
3195 u32, ok := value.(uint32)
3196 if ok {
3197 buf = make([]byte, 4)
3198 binary.BigEndian.PutUint32(buf, u32)
3199 } else {
3200 bytes, ok := value.([]byte)
3201 if ok {
3202 buf = bytes
3203 } else {
3204 assert.True(t, false) // Unknown attribute type
3205 }
3206 }
3207 }
3208 }
3209 attributeData = append(attributeData, buf...)
3210 }
3211 attributeMask := 0xfffc
3212 msgLength := len(attributeData) + 7
3213 // Results is 0 ("00"), and the two optional attribute masks are 0 ("00000000") as well
3214 goodMessage := "035e290b01010000" + fmt.Sprintf("%04x", msgLength) +
3215 "00" + fmt.Sprintf("%04x", attributeMask) + "00000000" + packetToString(attributeData)
3216
3217 data, err := stringToPacket(goodMessage)
3218 assert.NotNil(t, data)
3219 assert.Nil(t, err)
3220
3221 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3222 assert.NotNil(t, packet)
3223
3224 omciLayer := packet.Layer(LayerTypeOMCI)
3225 assert.NotNil(t, omciLayer)
3226
3227 omciMsg, ok := omciLayer.(*OMCI)
3228 assert.True(t, ok)
3229 assert.Equal(t, omciMsg.TransactionID, uint16(0x035e))
3230 assert.Equal(t, omciMsg.MessageType, GetResponseType)
3231 assert.Equal(t, omciMsg.DeviceIdentifier, ExtendedIdent)
3232 assert.Equal(t, omciMsg.Length, uint16(msgLength))
3233
3234 msgLayer := packet.Layer(LayerTypeGetResponse)
3235 assert.NotNil(t, msgLayer)
3236
3237 response, ok2 := msgLayer.(*GetResponse)
3238 assert.True(t, ok2)
3239 assert.NotNil(t, response)
3240 assert.Equal(t, response.Result, me.Success)
3241 assert.Equal(t, response.AttributeMask, uint16(attributeMask))
3242 assert.Equal(t, response.FailedAttributeMask, uint16(0))
3243 assert.Equal(t, response.UnsupportedAttributeMask, uint16(0))
3244
3245 assert.Equal(t, response.Attributes["EquipmentId"], toOctets("AAAAAAAAAAAAAAAAAAAAAAAAAAA="))
3246 assert.Equal(t, response.Attributes["OpticalNetworkUnitManagementAndControlChannelOmccVersion"], byte(0xb4)) // )
3247 assert.Equal(t, response.Attributes["VendorProductCode"], uint16(0x1234))
3248 assert.Equal(t, response.Attributes["SecurityCapability"], byte(1))
3249 assert.Equal(t, response.Attributes["SecurityMode"], byte(1))
3250 assert.Equal(t, response.Attributes["TotalPriorityQueueNumber"], uint16(0x5678))
3251 assert.Equal(t, response.Attributes["TotalTrafficSchedulerNumber"], byte(0x44))
3252 assert.Equal(t, response.Attributes["Deprecated"], byte(1))
3253 assert.Equal(t, response.Attributes["TotalGemPortIdNumber"], uint16(0x55aa))
3254 assert.Equal(t, response.Attributes["Sysuptime"], uint32(0xC4108011))
3255 assert.Equal(t, response.Attributes["ConnectivityCapability"], uint16(0x6))
3256 assert.Equal(t, response.Attributes["CurrentConnectivityMode"], byte(6))
3257 assert.Equal(t, response.Attributes["QualityOfServiceQosConfigurationFlexibility"], uint16(2))
3258 assert.Equal(t, response.Attributes["PriorityQueueScaleFactor"], uint16(0x1234))
3259
3260 // Verify string output for message
3261 packetString := packet.String()
3262 assert.NotZero(t, len(packetString))
3263}
3264
3265func TestExtendedGetResponseSerialize(t *testing.T) {
3266 goodMessage := "035e290b01010000003100fffc" +
3267 "000000000000000000000000000000000000000000000000" +
3268 "b4123401015678440155aac410801100060600021234"
3269
3270 omciLayer := &OMCI{
3271 TransactionID: 0x035e,
3272 MessageType: GetResponseType,
3273 DeviceIdentifier: ExtendedIdent,
3274 // Length parameter is optional for Extended message format serialization
3275 // and if present it will be overwritten during the serialization with the
3276 // actual value.
3277 }
3278 request := &GetResponse{
3279 MeBasePacket: MeBasePacket{
3280 EntityClass: me.Onu2GClassID,
3281 EntityInstance: uint16(0),
3282 Extended: true,
3283 },
3284 Result: 0,
3285 AttributeMask: uint16(0xfffc),
3286 Attributes: me.AttributeValueMap{
3287 "EquipmentId": toOctets("AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
3288 "OpticalNetworkUnitManagementAndControlChannelOmccVersion": byte(0xb4),
3289 "VendorProductCode": uint16(0x1234),
3290 "SecurityCapability": byte(1),
3291 "SecurityMode": byte(1),
3292 "TotalPriorityQueueNumber": uint16(0x5678),
3293 "TotalTrafficSchedulerNumber": byte(0x44),
3294 "Deprecated": byte(1),
3295 "TotalGemPortIdNumber": uint16(0x55aa),
3296 "Sysuptime": uint32(0xC4108011),
3297 "ConnectivityCapability": uint16(0x6),
3298 "CurrentConnectivityMode": byte(6),
3299 "QualityOfServiceQosConfigurationFlexibility": uint16(2),
3300 "PriorityQueueScaleFactor": uint16(0x1234),
3301 },
3302 }
3303 // Test serialization back to former string
3304 var options gopacket.SerializeOptions
3305 options.FixLengths = true
3306
3307 buffer := gopacket.NewSerializeBuffer()
3308 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3309 assert.NoError(t, err)
3310
3311 outgoingPacket := buffer.Bytes()
3312 reconstituted := packetToString(outgoingPacket)
3313 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3314}
3315
Chip Boling00a30d22021-05-04 13:31:52 -05003316// 1 2 3 4
3317// 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
3318// 0008140a00070001 - Download section, AR=0
3319// cc - Section 0xcc
3320// 01020304050607080910111213141516171819202122232425262728293031
3321// 00000028
3322func TestExtendedDownloadSectionRequestDecodeNoResponseExpected(t *testing.T) {
3323 goodMessage := "0008140b00070001"
3324 payloadFragment := "01020304050607080910111213141516171819202122232425"
3325 payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment +
3326 payloadFragment + payloadFragment + payloadFragment + payloadFragment
3327 sectionNumber := 0x88
3328 length := 1 + (8 * 25)
3329 hdr := fmt.Sprintf("%04x%02x", length, sectionNumber)
3330 goodMessage += hdr + payloadTotal
3331 data, err := stringToPacket(goodMessage)
3332 assert.NoError(t, err)
3333
3334 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3335 assert.NotNil(t, packet)
3336 assert.Nil(t, packet.ErrorLayer())
3337
3338 omciLayer := packet.Layer(LayerTypeOMCI)
3339 assert.NotNil(t, omciLayer)
3340
3341 omciMsg, ok := omciLayer.(*OMCI)
3342 assert.True(t, ok)
3343 assert.Equal(t, uint16(0x0008), omciMsg.TransactionID)
3344 assert.Equal(t, DownloadSectionRequestType, omciMsg.MessageType)
3345 assert.False(t, omciMsg.ResponseExpected)
3346 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
3347 assert.Equal(t, uint16(length), omciMsg.Length)
3348
3349 msgLayer := packet.Layer(LayerTypeDownloadSectionRequest)
3350 assert.NotNil(t, msgLayer)
3351
3352 request, ok2 := msgLayer.(*DownloadSectionRequest)
3353 assert.True(t, ok2)
3354 assert.NotNil(t, request)
3355 assert.Equal(t, uint8(sectionNumber), request.SectionNumber)
3356 assert.Equal(t, length-1, len(request.SectionData))
3357
3358 data, err = stringToPacket(payloadTotal)
3359 assert.NoError(t, err)
3360 assert.Equal(t, data, request.SectionData[:])
3361
3362 // Verify string output for message
3363 packetString := packet.String()
3364 assert.NotZero(t, len(packetString))
3365}
3366
3367func TestExtendedDownloadSectionRequestDecodeResponseExpected(t *testing.T) {
3368 goodMessage := "0008540b00070001"
3369 payloadFragment := "01020304050607080910111213141516171819202122232425"
3370 payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment +
3371 payloadFragment + payloadFragment + payloadFragment + payloadFragment +
3372 payloadFragment + payloadFragment + payloadFragment + payloadFragment +
3373 payloadFragment + payloadFragment + payloadFragment + payloadFragment +
3374 payloadFragment + payloadFragment + payloadFragment + payloadFragment
3375 sectionNumber := 0x88
3376 length := 1 + (20 * 25)
3377 hdr := fmt.Sprintf("%04x%02x", length, sectionNumber)
3378 goodMessage += hdr + payloadTotal
3379 data, err := stringToPacket(goodMessage)
3380 assert.NoError(t, err)
3381
3382 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3383 assert.NotNil(t, packet)
3384 assert.Nil(t, packet.ErrorLayer())
3385
3386 omciLayer := packet.Layer(LayerTypeOMCI)
3387 assert.NotNil(t, omciLayer)
3388
3389 omciMsg, ok := omciLayer.(*OMCI)
3390 assert.True(t, ok)
3391 assert.Equal(t, uint16(0x0008), omciMsg.TransactionID)
3392 assert.Equal(t, DownloadSectionRequestWithResponseType, omciMsg.MessageType)
3393 assert.True(t, omciMsg.ResponseExpected)
3394 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
3395 assert.Equal(t, uint16(length), omciMsg.Length)
3396
3397 msgLayer := packet.Layer(LayerTypeDownloadSectionRequest)
3398 assert.NotNil(t, msgLayer)
3399
3400 request, ok2 := msgLayer.(*DownloadSectionRequest)
3401 assert.True(t, ok2)
3402 assert.NotNil(t, request)
3403 assert.Equal(t, uint8(sectionNumber), request.SectionNumber)
3404 assert.Equal(t, length-1, len(request.SectionData))
3405
3406 data, err = stringToPacket(payloadTotal)
3407 assert.NoError(t, err)
3408 assert.Equal(t, data, request.SectionData)
3409
3410 // Verify string output for message
3411 packetString := packet.String()
3412 assert.NotZero(t, len(packetString))
3413}
3414
3415func TestExtendedDownloadSectionRequestDecodeTruncated(t *testing.T) {
3416 goodMessage := "0008540b000700010000"
3417 data, err := stringToPacket(goodMessage)
3418 assert.NoError(t, err)
3419
3420 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3421 assert.NotNil(t, packet)
3422
3423 failure := packet.ErrorLayer()
3424 assert.NotNil(t, failure)
3425
3426 decodeFailure, ok := failure.(*gopacket.DecodeFailure)
3427 assert.NotNil(t, decodeFailure)
3428 assert.True(t, ok)
3429 assert.NotNil(t, decodeFailure.String())
3430 assert.True(t, len(decodeFailure.String()) > 0)
3431
3432 metadata := packet.Metadata()
3433 assert.NotNil(t, metadata)
3434 assert.True(t, metadata.Truncated)
3435
3436 // Verify string output for message
3437 packetString := packet.String()
3438 assert.NotZero(t, len(packetString))
3439}
3440
3441func TestExtendedDownloadSectionRequestSerializeNoResponseExpected(t *testing.T) {
3442 goodMessage := "0123140b00070001"
3443 payloadFragment := "01020304050607080910111213141516171819202122232425"
3444 payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment +
3445 payloadFragment + payloadFragment + payloadFragment + payloadFragment
3446 sectionNumber := 0x84
3447 length := 1 + (8 * 25)
3448 hdr := fmt.Sprintf("%04x%02x", length, sectionNumber)
3449 goodMessage += hdr + payloadTotal
3450
3451 omciLayer := &OMCI{
3452 TransactionID: 0x0123,
3453 MessageType: DownloadSectionRequestType,
3454 DeviceIdentifier: ExtendedIdent,
3455 }
3456 sectionData, genErr := stringToPacket(payloadTotal)
3457 assert.Nil(t, genErr)
3458 assert.NotNil(t, sectionData)
3459 assert.Equal(t, len(payloadTotal)/2, len(sectionData))
3460
3461 request := &DownloadSectionRequest{
3462 MeBasePacket: MeBasePacket{
3463 EntityClass: me.SoftwareImageClassID,
3464 EntityInstance: uint16(1),
3465 Extended: true,
3466 },
3467 SectionNumber: byte(sectionNumber),
3468 SectionData: sectionData,
3469 }
3470 // Test serialization back to former string
3471 var options gopacket.SerializeOptions
3472 options.FixLengths = true
3473
3474 buffer := gopacket.NewSerializeBuffer()
3475 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3476 assert.NoError(t, err)
3477
3478 outgoingPacket := buffer.Bytes()
3479 reconstituted := packetToString(outgoingPacket)
3480 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3481}
3482
3483func TestExtendedDownloadSectionRequestSerializeResponseExpectedMethod1(t *testing.T) {
3484 goodMessage := "2468540b00070001"
3485 payloadFragment := "01020304050607080910111213141516171819202122232425"
3486 payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment +
3487 payloadFragment + payloadFragment + payloadFragment + payloadFragment
3488 sectionNumber := 0x84
3489 length := 1 + (8 * 25)
3490 hdr := fmt.Sprintf("%04x%02x", length, sectionNumber)
3491 goodMessage += hdr + payloadTotal
3492
3493 omciLayer := &OMCI{
3494 TransactionID: 0x2468,
3495 MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType
3496 ResponseExpected: true,
3497 DeviceIdentifier: ExtendedIdent,
3498 }
3499 sectionData, genErr := stringToPacket(payloadTotal)
3500 assert.Nil(t, genErr)
3501 assert.NotNil(t, sectionData)
3502 assert.Equal(t, len(payloadTotal)/2, len(sectionData))
3503
3504 request := &DownloadSectionRequest{
3505 MeBasePacket: MeBasePacket{
3506 EntityClass: me.SoftwareImageClassID,
3507 EntityInstance: uint16(1),
3508 Extended: true,
3509 },
3510 SectionNumber: byte(sectionNumber),
3511 SectionData: sectionData,
3512 }
3513 // Test serialization back to former string
3514 var options gopacket.SerializeOptions
3515 options.FixLengths = true
3516
3517 buffer := gopacket.NewSerializeBuffer()
3518 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3519 assert.NoError(t, err)
3520
3521 outgoingPacket := buffer.Bytes()
3522 reconstituted := packetToString(outgoingPacket)
3523 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3524}
3525
3526func TestExtendedDownloadSectionRequestSerializeResponseExpectedMethod2(t *testing.T) {
3527 goodMessage := "2468540b00070001"
3528 payloadFragment := "01020304050607080910111213141516171819202122232425"
3529 payloadTotal := payloadFragment + payloadFragment + payloadFragment + payloadFragment +
3530 payloadFragment + payloadFragment + payloadFragment + payloadFragment
3531 sectionNumber := 0x84
3532 length := 1 + (8 * 25)
3533 hdr := fmt.Sprintf("%04x%02x", length, sectionNumber)
3534 goodMessage += hdr + payloadTotal
3535
3536 // In this case, just use the request type with AR response requested already encoded
3537 omciLayer := &OMCI{
3538 TransactionID: 0x2468,
3539 MessageType: DownloadSectionRequestWithResponseType,
3540 ResponseExpected: true,
3541 DeviceIdentifier: ExtendedIdent,
3542 }
3543 sectionData, genErr := stringToPacket(payloadTotal)
3544 assert.Nil(t, genErr)
3545 assert.NotNil(t, sectionData)
3546 assert.Equal(t, len(payloadTotal)/2, len(sectionData))
3547
3548 request := &DownloadSectionRequest{
3549 MeBasePacket: MeBasePacket{
3550 EntityClass: me.SoftwareImageClassID,
3551 EntityInstance: 0x0001, // Default is zero, here we want image 1
3552 Extended: true,
3553 },
3554 SectionNumber: byte(sectionNumber),
3555 SectionData: sectionData,
3556 }
3557 // Test serialization back to former string
3558 var options gopacket.SerializeOptions
3559 options.FixLengths = true
3560
3561 buffer := gopacket.NewSerializeBuffer()
3562 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3563 assert.NoError(t, err)
3564
3565 outgoingPacket := buffer.Bytes()
3566 reconstituted := packetToString(outgoingPacket)
3567 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3568}
3569
3570func TestExtendedDownloadSectionResponseDecode(t *testing.T) {
3571 goodMessage := "0022340b000700010002061f"
3572 data, err := stringToPacket(goodMessage)
3573 assert.NoError(t, err)
3574
3575 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3576 assert.NotNil(t, packet)
3577
3578 omciLayer := packet.Layer(LayerTypeOMCI)
3579 assert.NotNil(t, omciLayer)
3580
3581 omciMsg, ok := omciLayer.(*OMCI)
3582 assert.True(t, ok)
3583 assert.Equal(t, omciMsg.TransactionID, uint16(0x0022))
3584 assert.Equal(t, omciMsg.MessageType, DownloadSectionResponseType)
3585 assert.Equal(t, omciMsg.DeviceIdentifier, ExtendedIdent)
3586 assert.Equal(t, uint16(2), omciMsg.Length)
3587
3588 msgLayer := packet.Layer(LayerTypeDownloadSectionResponse)
3589 assert.NotNil(t, msgLayer)
3590
3591 response, ok2 := msgLayer.(*DownloadSectionResponse)
3592 assert.True(t, ok2)
3593 assert.NotNil(t, response)
3594 assert.Equal(t, me.DeviceBusy, response.Result)
3595 assert.Equal(t, byte(0x1f), response.SectionNumber)
3596
3597 // Verify string output for message
3598 packetString := packet.String()
3599 assert.NotZero(t, len(packetString))
3600}
3601
3602func TestExtendedDownloadSectionResponseDecodeTruncated(t *testing.T) {
3603 goodMessage := "0022340b00070001000106"
3604 data, err := stringToPacket(goodMessage)
3605 assert.NoError(t, err)
3606
3607 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3608 assert.NotNil(t, packet)
3609
3610 failure := packet.ErrorLayer()
3611 assert.NotNil(t, failure)
3612
3613 decodeFailure, ok := failure.(*gopacket.DecodeFailure)
3614 assert.NotNil(t, decodeFailure)
3615 assert.True(t, ok)
3616 assert.NotNil(t, decodeFailure.String())
3617 assert.True(t, len(decodeFailure.String()) > 0)
3618
3619 metadata := packet.Metadata()
3620 assert.NotNil(t, metadata)
3621 assert.True(t, metadata.Truncated)
3622
3623 // Verify string output for message
3624 packetString := packet.String()
3625 assert.NotZero(t, len(packetString))
3626}
3627
3628func TestExtendedDownloadSectionResponseSerialize(t *testing.T) {
3629 goodMessage := "0022340b000700010002061f"
3630
3631 omciLayer := &OMCI{
3632 TransactionID: 0x0022,
3633 MessageType: DownloadSectionResponseType,
3634 DeviceIdentifier: ExtendedIdent,
3635 }
3636 request := &DownloadSectionResponse{
3637 MeBasePacket: MeBasePacket{
3638 EntityClass: me.SoftwareImageClassID,
3639 EntityInstance: 1,
3640 Extended: true,
3641 },
3642 Result: me.DeviceBusy,
3643 SectionNumber: 0x1f,
3644 }
3645 // Test serialization back to former string
3646 var options gopacket.SerializeOptions
3647 options.FixLengths = true
3648
3649 buffer := gopacket.NewSerializeBuffer()
3650 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3651 assert.NoError(t, err)
3652
3653 outgoingPacket := buffer.Bytes()
3654 reconstituted := packetToString(outgoingPacket)
3655 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3656}
3657
Chip Bolingd8637b02021-04-29 08:36:38 -05003658func TestGenericTestResultDecode(t *testing.T) {
3659 // ONU-G ME for this test with just made up data
3660 payload := "1234567890123456789012345678901234567890123456789012345678901234"
3661 goodMessage := "00001b0a01000000" + payload + "00000028"
3662 data, err := stringToPacket(goodMessage)
3663 assert.NoError(t, err)
3664
3665 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3666 assert.NotNil(t, packet)
3667
3668 omciLayer := packet.Layer(LayerTypeOMCI)
3669 assert.NotNil(t, omciLayer)
3670
3671 omciMsg, ok := omciLayer.(*OMCI)
3672 assert.True(t, ok)
3673 assert.Equal(t, omciMsg.TransactionID, uint16(0x0000))
3674 assert.Equal(t, omciMsg.MessageType, TestResultType)
3675 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
3676 assert.Equal(t, uint16(40), omciMsg.Length)
3677
3678 msgLayer := packet.Layer(LayerTypeTestResult)
3679 assert.NotNil(t, msgLayer)
3680
3681 // This is a generic struct since we do not do detailed decode
3682 generic, ok2 := msgLayer.(*TestResultNotification)
3683 assert.True(t, ok2)
3684 assert.NotNil(t, generic)
3685 assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data
3686 assert.NotNil(t, generic.Payload)
3687 assert.NotNil(t, generic.TestResults())
3688
3689 base := generic.MeBasePacket
3690 assert.Equal(t, me.OnuGClassID, base.EntityClass)
3691 assert.Equal(t, uint16(0), base.EntityInstance)
3692
3693 // For the generic Test Result, get the payload data which is all the data in
3694 // the test notification past the Entity Instance value.
3695 payloadData, payloadErr := stringToPacket(payload)
3696 assert.NotNil(t, payloadData)
3697 assert.NoError(t, payloadErr)
3698 assert.Equal(t, payloadData, base.Payload)
3699 assert.Equal(t, payloadData, generic.Payload)
3700
3701 // Verify string output for message
3702 packetString := packet.String()
3703 assert.NotZero(t, len(packetString))
3704}
3705
3706func TestOpticalLineSupervisionTestResultDecode(t *testing.T) {
3707 // ANI-G ME for this test with just made up data
3708 payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901" + "000000000000000000000000000000"
3709 goodMessage := "00001b0a01078001" + payload + "00000028"
3710 data, err := stringToPacket(goodMessage)
3711 assert.NoError(t, err)
3712
3713 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3714 assert.NotNil(t, packet)
3715
3716 omciLayer := packet.Layer(LayerTypeOMCI)
3717 assert.NotNil(t, omciLayer)
3718
3719 omciMsg, ok := omciLayer.(*OMCI)
3720 assert.True(t, ok)
3721 assert.Equal(t, omciMsg.TransactionID, uint16(0x0000))
3722 assert.Equal(t, omciMsg.MessageType, TestResultType)
3723 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
3724 assert.Equal(t, uint16(40), omciMsg.Length)
3725
3726 msgLayer := packet.Layer(LayerTypeTestResult)
3727 assert.NotNil(t, msgLayer)
3728
3729 // This is a optical line test results
3730 optical, ok2 := msgLayer.(*OpticalLineSupervisionTestResult)
3731 assert.True(t, ok2)
3732 assert.NotNil(t, optical)
3733
3734 // Get the Managed Entity class ID and instance ID from the base packet
3735 base := optical.MeBasePacket
3736 assert.Equal(t, me.AniGClassID, base.EntityClass)
3737 assert.Equal(t, uint16(0x8001), base.EntityInstance)
3738
3739 assert.Equal(t, uint8(1), optical.PowerFeedVoltageType)
3740 assert.Equal(t, uint16(0x34), optical.PowerFeedVoltage)
3741
3742 assert.Equal(t, uint8(3), optical.ReceivedOpticalPowerType)
3743 assert.Equal(t, uint16(0x67), optical.ReceivedOpticalPower)
3744
3745 assert.Equal(t, uint8(5), optical.MeanOpticalLaunchType)
3746 assert.Equal(t, uint16(0x91), optical.MeanOpticalLaunch)
3747
3748 assert.Equal(t, uint8(9), optical.LaserBiasCurrentType)
3749 assert.Equal(t, uint16(0x34), optical.LaserBiasCurrent)
3750
3751 assert.Equal(t, uint8(12), optical.TemperatureType)
3752 assert.Equal(t, uint16(0x67), optical.Temperature)
3753
3754 assert.Equal(t, uint16(0x8901), optical.GeneralPurposeBuffer)
3755
3756 // Verify string output for message
3757 packetString := packet.String()
3758 assert.NotZero(t, len(packetString))
3759}
3760
3761func TestGenericTestResultSerialize(t *testing.T) {
3762 payload := "1234567891234567890123456789012345678901234567890123456789012345"
3763 goodMessage := "00001b0a01000000" + payload + "00000028"
3764
3765 omciLayer := &OMCI{
3766 // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000
3767 MessageType: TestResultType,
3768 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
3769 // Length: 0x28, // Optional, defaults to 40 octets
3770 }
3771 data, derr := stringToPacket(payload)
3772 assert.NoError(t, derr)
3773
3774 request := &TestResultNotification{
3775 MeBasePacket: MeBasePacket{
3776 EntityClass: me.OnuGClassID,
3777 EntityInstance: uint16(0),
3778 },
3779 Payload: data,
3780 }
3781 // Test serialization back to former string
3782 var options gopacket.SerializeOptions
3783 options.FixLengths = true
3784
3785 buffer := gopacket.NewSerializeBuffer()
3786 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3787 assert.NoError(t, err)
3788
3789 outgoingPacket := buffer.Bytes()
3790 reconstituted := packetToString(outgoingPacket)
3791 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3792}
3793
3794func TestOpticalLineSupervisionTestResultSerialize(t *testing.T) {
3795 // ANI-G ME for this test with just made up data
3796 payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901" + "000000000000000000000000000000"
3797 goodMessage := "00001b0a01078001" + payload + "00000028"
3798
3799 omciLayer := &OMCI{
3800 // TransactionID: 0x0c, // Optional for notifications since TID always 0x0000
3801 MessageType: TestResultType,
3802 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
3803 // Length: 0x28, // Optional, defaults to 40 octets
3804 }
3805 request := &OpticalLineSupervisionTestResult{
3806 MeBasePacket: MeBasePacket{
3807 EntityClass: me.AniGClassID,
3808 EntityInstance: uint16(0x8001),
3809 },
3810 PowerFeedVoltageType: uint8(1),
3811 PowerFeedVoltage: uint16(0x34),
3812 ReceivedOpticalPowerType: uint8(3),
3813 ReceivedOpticalPower: uint16(0x67),
3814 MeanOpticalLaunchType: uint8(5),
3815 MeanOpticalLaunch: uint16(0x91),
3816 LaserBiasCurrentType: uint8(9),
3817 LaserBiasCurrent: uint16(0x34),
3818 TemperatureType: uint8(12),
3819 Temperature: uint16(0x67),
3820 GeneralPurposeBuffer: uint16(0x8901),
3821 }
3822 // Test serialization back to former string
3823 var options gopacket.SerializeOptions
3824 options.FixLengths = true
3825
3826 buffer := gopacket.NewSerializeBuffer()
3827 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3828 assert.NoError(t, err)
3829
3830 outgoingPacket := buffer.Bytes()
3831 reconstituted := packetToString(outgoingPacket)
3832 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3833}
3834
3835func TestGenericTestRequestDecode(t *testing.T) {
3836 // ONU-G ME for this test with just made up data
3837 payload := "1234567890523456789012345678901234567890123456789012345678901234"
3838 goodMessage := "0123520a01000000" + payload + "00000028"
3839 data, err := stringToPacket(goodMessage)
3840 assert.NoError(t, err)
3841
3842 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3843 assert.NotNil(t, packet)
3844
3845 omciLayer := packet.Layer(LayerTypeOMCI)
3846 assert.NotNil(t, omciLayer)
3847
3848 omciMsg, ok := omciLayer.(*OMCI)
3849 assert.True(t, ok)
3850 assert.Equal(t, uint16(0x0123), omciMsg.TransactionID)
3851 assert.Equal(t, TestRequestType, omciMsg.MessageType)
3852 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
3853 assert.Equal(t, uint16(40), omciMsg.Length)
3854
3855 msgLayer := packet.Layer(LayerTypeTestResult)
3856 assert.NotNil(t, msgLayer)
3857
3858 // This is a generic struct since we do not do detailed decode
3859 generic, ok2 := msgLayer.(*TestRequest)
3860 assert.True(t, ok2)
3861 assert.NotNil(t, generic)
3862 assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data
3863 assert.NotNil(t, generic.Payload)
3864 assert.NotNil(t, generic.TestRequest())
3865
3866 base := generic.MeBasePacket
3867 assert.Equal(t, me.OnuGClassID, base.EntityClass)
3868 assert.Equal(t, uint16(0), base.EntityInstance)
3869
3870 // For the generic Test Result, get the payload data which is all the data in
3871 // the test notification past the Entity Instance value.
3872 payloadData, payloadErr := stringToPacket(payload)
3873 assert.NotNil(t, payloadData)
3874 assert.NoError(t, payloadErr)
3875 assert.Equal(t, payloadData, base.Payload)
3876 assert.Equal(t, payloadData, generic.Payload)
3877
3878 // Verify string output for message
3879 packetString := packet.String()
3880 assert.NotZero(t, len(packetString))
3881}
3882
3883func TestOpticalLineSupervisionTestRequestDecode(t *testing.T) {
3884 // ANI-G ME for this test with just made up data
3885 payload := "01" + "1234" + "5678" + "000000000000000000000000000000000000000000000000000000"
3886 goodMessage := "0ddd520a01078001" + payload + "00000028"
3887 data, err := stringToPacket(goodMessage)
3888 assert.NoError(t, err)
3889
3890 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3891 assert.NotNil(t, packet)
3892
3893 omciLayer := packet.Layer(LayerTypeOMCI)
3894 assert.NotNil(t, omciLayer)
3895
3896 omciMsg, ok := omciLayer.(*OMCI)
3897 assert.True(t, ok)
3898 assert.Equal(t, uint16(0x0ddd), omciMsg.TransactionID)
3899 assert.Equal(t, TestRequestType, omciMsg.MessageType)
3900 assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
3901 assert.Equal(t, uint16(40), omciMsg.Length)
3902
3903 msgLayer := packet.Layer(LayerTypeTestResult)
3904 assert.NotNil(t, msgLayer)
3905
3906 // This is a optical line test results
3907 optical, ok2 := msgLayer.(*OpticalLineSupervisionTestRequest)
3908 assert.True(t, ok2)
3909 assert.NotNil(t, optical)
3910
3911 // Get the Managed Entity class ID and instance ID from the base packet
3912 base := optical.MeBasePacket
3913 assert.Equal(t, me.AniGClassID, base.EntityClass)
3914 assert.Equal(t, uint16(0x8001), base.EntityInstance)
3915
3916 assert.Equal(t, uint8(1), optical.SelectTest)
3917 assert.Equal(t, uint16(0x1234), optical.GeneralPurposeBuffer)
3918 assert.Equal(t, uint16(0x5678), optical.VendorSpecificParameters)
3919
3920 // Verify string output for message
3921 packetString := packet.String()
3922 assert.NotZero(t, len(packetString))
3923}
3924
3925func TestGenericTestRequestSerialize(t *testing.T) {
3926 payload := "1234567891234567890123456789012345678901234567890123456789012345"
3927 goodMessage := "eeee520a01000000" + payload + "00000028"
3928
3929 omciLayer := &OMCI{
3930 TransactionID: 0xeeee,
3931 MessageType: TestRequestType,
3932 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
3933 // Length: 0x28, // Optional, defaults to 40 octets
3934 }
3935 data, derr := stringToPacket(payload)
3936 assert.NoError(t, derr)
3937
3938 request := &TestRequest{
3939 MeBasePacket: MeBasePacket{
3940 EntityClass: me.OnuGClassID,
3941 EntityInstance: uint16(0),
3942 },
3943 Payload: data,
3944 }
3945 // Test serialization back to former string
3946 var options gopacket.SerializeOptions
3947 options.FixLengths = true
3948
3949 buffer := gopacket.NewSerializeBuffer()
3950 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3951 assert.NoError(t, err)
3952
3953 outgoingPacket := buffer.Bytes()
3954 reconstituted := packetToString(outgoingPacket)
3955 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3956}
3957
3958func TestOpticalLineSupervisionTestRequestSerialize(t *testing.T) {
3959 // ANI-G ME for this test with just made up data
3960 payload := "01" + "1234" + "5678" + "000000000000000000000000000000000000000000000000000000"
3961 goodMessage := "bbbb520a01078001" + payload + "00000028"
3962
3963 omciLayer := &OMCI{
3964 TransactionID: 0xbbbb,
3965 MessageType: TestRequestType,
3966 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
3967 // Length: 0x28, // Optional, defaults to 40 octets
3968 }
3969 request := &OpticalLineSupervisionTestRequest{
3970 MeBasePacket: MeBasePacket{
3971 EntityClass: me.AniGClassID,
3972 EntityInstance: uint16(0x8001),
3973 },
3974 SelectTest: uint8(1),
3975 GeneralPurposeBuffer: uint16(0x1234),
3976 VendorSpecificParameters: uint16(0x5678),
3977 }
3978 // Test serialization back to former string
3979 var options gopacket.SerializeOptions
3980 options.FixLengths = true
3981
3982 buffer := gopacket.NewSerializeBuffer()
3983 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
3984 assert.NoError(t, err)
3985
3986 outgoingPacket := buffer.Bytes()
3987 reconstituted := packetToString(outgoingPacket)
3988 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
3989}
3990
3991func TestTestResponseDecode(t *testing.T) {
3992 goodMessage := "0001320A01000000000000000000000000000000000000000000000000000000000000000000000000000028"
3993 data, err := stringToPacket(goodMessage)
3994 assert.NoError(t, err)
3995
3996 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
3997 assert.NotNil(t, packet)
3998
3999 omciLayer := packet.Layer(LayerTypeOMCI)
4000 assert.NotNil(t, omciLayer)
4001
4002 omciMsg, ok := omciLayer.(*OMCI)
4003 assert.True(t, ok)
4004 assert.Equal(t, TestResponseType, omciMsg.MessageType)
4005 assert.Equal(t, uint16(40), omciMsg.Length)
4006
4007 msgLayer := packet.Layer(LayerTypeTestResponse)
4008
4009 assert.NotNil(t, msgLayer)
4010
4011 response, ok2 := msgLayer.(*TestResponse)
4012 assert.True(t, ok2)
4013 assert.NotNil(t, response)
4014 assert.Equal(t, me.OnuGClassID, response.EntityClass)
4015 assert.Equal(t, uint16(0), response.EntityInstance)
4016 assert.Equal(t, me.Success, response.Result)
4017
4018 // Verify string output for message
4019 packetString := packet.String()
4020 assert.NotZero(t, len(packetString))
4021}
4022
4023func TestTestResponseSerialize(t *testing.T) {
4024 goodMessage := "0001320A01000000000000000000000000000000000000000000000000000000000000000000000000000028"
4025
4026 omciLayer := &OMCI{
4027 TransactionID: 0x01,
4028 MessageType: TestResponseType,
4029 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
4030 // Length: 0x28, // Optional, defaults to 40 octets
4031 }
4032 request := &TestResponse{
4033 MeBasePacket: MeBasePacket{
4034 EntityClass: me.OnuGClassID,
4035 // Default Instance ID is 0
4036 },
4037 Result: me.Success,
4038 }
4039 // Test serialization back to former string
4040 var options gopacket.SerializeOptions
4041 options.FixLengths = true
4042
4043 buffer := gopacket.NewSerializeBuffer()
4044 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
4045 assert.NoError(t, err)
4046
4047 outgoingPacket := buffer.Bytes()
4048 reconstituted := packetToString(outgoingPacket)
4049 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
4050}
4051
Chip Boling157c9b92021-04-21 09:58:36 -05004052// TODO: Also remember to add extended message tests to the meframe_test.go
4053// unit tests as more message types are supported