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