blob: 481470348180cf5799ea2ba625ae3a014743cba9 [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{
1743 TransactionID: 0x2468,
1744 MessageType: DownloadSectionRequestType, // or DownloadSectionRequestWithResponseType
1745 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{
1793 EntityClass: me.SoftwareImageClassID,
1794 EntityInstance: 0x0001, // Default is zero, here we want image 1
1795 },
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) {
1814 // TODO: Need to complete implementation & debug this
1815 //goodMessage := ""
1816 //data, err := stringToPacket(goodMessage)
1817 //assert.NoError(t, err)
1818 //
1819 //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
1820 //assert.NotNil(t, packet)
1821 //
1822 //omciLayer := packet.Layer(LayerTypeOMCI)
1823 //assert.NotNil(t, packet)
1824 //
1825 //omciMsg, ok := omciLayer.(*OMCI)
1826 //assert.True(t, ok)
1827 //assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
1828 //assert.Equal(t, omciMsg.MessageType, DownloadSectionResponseType)
1829 //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
1830 //assert.Equal(t, omciMsg.Length, uint16(40))
1831 //
1832 //msgLayer := packet.Layer(LayerTypeDownloadSectionResponse)
1833 //
1834 //assert.NotNil(t, msgLayer)
1835 //
1836 //response, ok2 := msgLayer.(*DownloadSectionResponse)
1837 //assert.True(t, ok2)
1838 //assert.NotNil(t, response)
1839 //
1840 //// Verify string output for message
1841 //packetString := packet.String()
1842 //assert.NotZero(t, len(packetString))
1843}
1844
1845func TestDownloadSectionResponseSerialize(t *testing.T) {
1846 // TODO: Need to complete implementation & debug this
1847 //goodMessage := ""
1848 //
1849 //omciLayer := &OMCI{
1850 // TransactionID: 0x01,
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{
Chip Boling8c8018e2021-02-22 15:56:00 -06001857 // EntityClass: me.OnuDataClassID,
Chip Boling6e27b352020-02-14 09:10:01 -06001858 // // Default Instance ID is 0
1859 // },
1860 //}
1861 //// Test serialization back to former string
1862 //var options gopacket.SerializeOptions
1863 //options.FixLengths = true
1864 //
1865 //buffer := gopacket.NewSerializeBuffer()
1866 //err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
1867 //assert.NoError(t, err)
1868 //
1869 //outgoingPacket := buffer.Bytes()
1870 //reconstituted := packetToString(outgoingPacket)
1871 //assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
1872}
1873
1874func TestEndSoftwareDownloadRequestDecode(t *testing.T) {
1875 // TODO: Need to complete implementation & debug this
1876 //goodMessage := "0000550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028"
1877 //data, err := stringToPacket(goodMessage)
1878 //assert.NoError(t, err)
1879 //
1880 //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
1881 //assert.NotNil(t, packet)
1882 //
1883 //omciLayer := packet.Layer(LayerTypeOMCI)
1884 //assert.NotNil(t, packet)
1885 //
1886 //omciMsg, ok := omciLayer.(*OMCI)
1887 //assert.True(t, ok)
1888 //assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
1889 //assert.Equal(t, omciMsg.MessageType, EndSoftwareDownloadRequestType)
1890 //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
1891 //assert.Equal(t, omciMsg.Length, uint16(40))
1892 //
1893 //msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadRequest)
1894 //assert.NotNil(t, msgLayer)
1895 //
1896 //request, ok2 := msgLayer.(*EndSoftwareDownloadRequest)
1897 //assert.True(t, ok2)
1898 //assert.NotNil(t, request)
1899 //
1900 //// Verify string output for message
1901 //packetString := packet.String()
1902 //assert.NotZero(t, len(packetString))
1903}
1904
1905func TestEndSoftwareDownloadRequestSerialize(t *testing.T) {
1906 // TODO: Need to complete implementation & debug this
1907 //goodMessage := "0000550a00070001ff92a226000f424001000100000000000000000000000000000000000000000000000028"
1908 //
1909 //omciLayer := &OMCI{
1910 // TransactionID: 0x01,
1911 // MessageType: EndSoftwareDownloadRequestType,
1912 // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
1913 // // Length: 0x28, // Optional, defaults to 40 octets
1914 //}
1915 //request := &EndSoftwareDownloadRequest{
1916 // MeBasePacket: MeBasePacket{
1917 // EntityClass: OnuDataClassID,
1918 // // Default Instance ID is 0
1919 // },
1920 //}
1921 //// Test serialization back to former string
1922 //var options gopacket.SerializeOptions
1923 //options.FixLengths = true
1924 //
1925 //buffer := gopacket.NewSerializeBuffer()
1926 //err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
1927 //assert.NoError(t, err)
1928 //
1929 //outgoingPacket := buffer.Bytes()
1930 //reconstituted := packetToString(outgoingPacket)
1931 //assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
1932}
1933
1934func TestEndSoftwareDownloadResponseDecode(t *testing.T) {
1935 // TODO: Need to complete implementation & debug this
1936 //goodMessage := ""
1937 //data, err := stringToPacket(goodMessage)
1938 //assert.NoError(t, err)
1939 //
1940 //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
1941 //assert.NotNil(t, packet)
1942 //
1943 //omciLayer := packet.Layer(LayerTypeOMCI)
1944 //assert.NotNil(t, packet)
1945 //
1946 //omciMsg, ok := omciLayer.(*OMCI)
1947 //assert.True(t, ok)
1948 //assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
1949 //assert.Equal(t, omciMsg.MessageType, EndSoftwareDownloadResponseType)
1950 //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
1951 //assert.Equal(t, omciMsg.Length, uint16(40))
1952 //
1953 //msgLayer := packet.Layer(LayerTypeEndSoftwareDownloadResponse)
1954 //
1955 //assert.NotNil(t, msgLayer)
1956 //
1957 //response, ok2 := msgLayer.(*EndSoftwareDownloadResponse)
1958 //assert.True(t, ok2)
1959 //assert.NotNil(t, response)
1960 //
1961 //// Verify string output for message
1962 //packetString := packet.String()
1963 //assert.NotZero(t, len(packetString))
1964}
1965
1966func TestEndSoftwareDownloadResponseSerialize(t *testing.T) {
1967 // TODO: Need to complete implementation & debug this
1968 //goodMessage := ""
1969 //
1970 //omciLayer := &OMCI{
1971 // TransactionID: 0x01,
1972 // MessageType: EndSoftwareDownloadResponseType,
1973 // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
1974 // // Length: 0x28, // Optional, defaults to 40 octets
1975 //}
1976 //request := &EndSoftwareDownloadResponse{
1977 // MeBasePacket: MeBasePacket{
1978 // EntityClass: OnuDataClassID,
1979 // // Default Instance ID is 0
1980 // },
1981 //}
1982 //// Test serialization back to former string
1983 //var options gopacket.SerializeOptions
1984 //options.FixLengths = true
1985 //
1986 //buffer := gopacket.NewSerializeBuffer()
1987 //err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
1988 //assert.NoError(t, err)
1989 //
1990 //outgoingPacket := buffer.Bytes()
1991 //reconstituted := packetToString(outgoingPacket)
1992 //assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
1993}
1994
1995func TestActivateSoftwareRequestDecode(t *testing.T) {
1996 // TODO: Need to complete implementation & debug this
1997 //goodMessage := "0000560a00070001000000000000000000000000000000000000000000000000000000000000000000000028"
1998 //data, err := stringToPacket(goodMessage)
1999 //assert.NoError(t, err)
2000 //
2001 //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2002 //assert.NotNil(t, packet)
2003 //
2004 //omciLayer := packet.Layer(LayerTypeOMCI)
2005 //assert.NotNil(t, packet)
2006 //
2007 //omciMsg, ok := omciLayer.(*OMCI)
2008 //assert.True(t, ok)
2009 //assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2010 //assert.Equal(t, omciMsg.MessageType, ActivateSoftwareRequestType)
2011 //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2012 //assert.Equal(t, omciMsg.Length, uint16(40))
2013 //
2014 //msgLayer := packet.Layer(LayerTypeActivateSoftwareRequest)
2015 //assert.NotNil(t, msgLayer)
2016 //
2017 //request, ok2 := msgLayer.(*ActivateSoftwareRequest)
2018 //assert.True(t, ok2)
2019 //assert.NotNil(t, request)
2020 //
2021 //// Verify string output for message
2022 //packetString := packet.String()
2023 //assert.NotZero(t, len(packetString))
2024}
2025
2026func TestActivateSoftwareRequestSerialize(t *testing.T) {
2027 // TODO: Need to complete implementation & debug this
2028 //goodMessage := "0000560a00070001000000000000000000000000000000000000000000000000000000000000000000000028"
2029 //
2030 //omciLayer := &OMCI{
2031 // TransactionID: 0x01,
2032 // MessageType: ActivateSoftwareRequestType,
2033 // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2034 // // Length: 0x28, // Optional, defaults to 40 octets
2035 //}
2036 //request := &ActivateSoftwareRequest{
2037 // MeBasePacket: MeBasePacket{
2038 // EntityClass: OnuDataClassID,
2039 // // Default Instance ID is 0
2040 // },
2041 //}
2042 //// Test serialization back to former string
2043 //var options gopacket.SerializeOptions
2044 //options.FixLengths = true
2045 //
2046 //buffer := gopacket.NewSerializeBuffer()
2047 //err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2048 //assert.NoError(t, err)
2049 //
2050 //outgoingPacket := buffer.Bytes()
2051 //reconstituted := packetToString(outgoingPacket)
2052 //assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2053}
2054
2055func TestActivateSoftwareResponseDecode(t *testing.T) {
2056 // TODO: Need to complete implementation & debug this
2057 //goodMessage := ""
2058 //data, err := stringToPacket(goodMessage)
2059 //assert.NoError(t, err)
2060 //
2061 //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2062 //assert.NotNil(t, packet)
2063 //
2064 //omciLayer := packet.Layer(LayerTypeOMCI)
2065 //assert.NotNil(t, packet)
2066 //
2067 //omciMsg, ok := omciLayer.(*OMCI)
2068 //assert.True(t, ok)
2069 //assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2070 //assert.Equal(t, omciMsg.MessageType, ActivateSoftwareResponseType)
2071 //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2072 //assert.Equal(t, omciMsg.Length, uint16(40))
2073 //
2074 //msgLayer := packet.Layer(LayerTypeActivateSoftwareResponse)
2075 //
2076 //assert.NotNil(t, msgLayer)
2077 //
2078 //response, ok2 := msgLayer.(*ActivateSoftwareResponse)
2079 //assert.True(t, ok2)
2080 //assert.NotNil(t, response)
2081 //
2082 //// Verify string output for message
2083 //packetString := packet.String()
2084 //assert.NotZero(t, len(packetString))
2085}
2086
2087func TestActivateSoftwareResponseSerialize(t *testing.T) {
2088 // TODO: Need to complete implementation & debug this
2089 //goodMessage := ""
2090 //
2091 //omciLayer := &OMCI{
2092 // TransactionID: 0x01,
2093 // MessageType: ActivateSoftwareResponseType,
2094 // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2095 // // Length: 0x28, // Optional, defaults to 40 octets
2096 //}
2097 //request := &ActivateSoftwareResponse{
2098 // MeBasePacket: MeBasePacket{
2099 // EntityClass: OnuDataClassID,
2100 // // Default Instance ID is 0
2101 // },
2102 //}
2103 //// Test serialization back to former string
2104 //var options gopacket.SerializeOptions
2105 //options.FixLengths = true
2106 //
2107 //buffer := gopacket.NewSerializeBuffer()
2108 //err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2109 //assert.NoError(t, err)
2110 //
2111 //outgoingPacket := buffer.Bytes()
2112 //reconstituted := packetToString(outgoingPacket)
2113 //assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2114}
2115
2116func TestCommitSoftwareRequestDecode(t *testing.T) {
2117 // TODO: Need to complete implementation & debug this
2118 //goodMessage := "0000570a00070001000000000000000000000000000000000000000000000000000000000000000000000028"
2119 //data, err := stringToPacket(goodMessage)
2120 //assert.NoError(t, err)
2121 //
2122 //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2123 //assert.NotNil(t, packet)
2124 //
2125 //omciLayer := packet.Layer(LayerTypeOMCI)
2126 //assert.NotNil(t, packet)
2127 //
2128 //omciMsg, ok := omciLayer.(*OMCI)
2129 //assert.True(t, ok)
2130 //assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2131 //assert.Equal(t, omciMsg.MessageType, CommitSoftwareRequestType)
2132 //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2133 //assert.Equal(t, omciMsg.Length, uint16(40))
2134 //
2135 //msgLayer := packet.Layer(LayerTypeCommitSoftwareRequest)
2136 //assert.NotNil(t, msgLayer)
2137 //
2138 //request, ok2 := msgLayer.(*CommitSoftwareRequest)
2139 //assert.True(t, ok2)
2140 //assert.NotNil(t, request)
2141 //
2142 //// Verify string output for message
2143 //packetString := packet.String()
2144 //assert.NotZero(t, len(packetString))
2145}
2146
2147func TestCommitSoftwareRequestSerialize(t *testing.T) {
2148 // TODO: Need to complete implementation & debug this
2149 //goodMessage := "0000570a00070001000000000000000000000000000000000000000000000000000000000000000000000028"
2150 //
2151 //omciLayer := &OMCI{
2152 // TransactionID: 0x01,
2153 // MessageType: CommitSoftwareRequestType,
2154 // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2155 // // Length: 0x28, // Optional, defaults to 40 octets
2156 //}
2157 //request := &CommitSoftwareRequest{
2158 // MeBasePacket: MeBasePacket{
2159 // EntityClass: OnuDataClassID,
2160 // // Default Instance ID is 0
2161 // },
2162 //}
2163 //// Test serialization back to former string
2164 //var options gopacket.SerializeOptions
2165 //options.FixLengths = true
2166 //
2167 //buffer := gopacket.NewSerializeBuffer()
2168 //err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2169 //assert.NoError(t, err)
2170 //
2171 //outgoingPacket := buffer.Bytes()
2172 //reconstituted := packetToString(outgoingPacket)
2173 //assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2174}
2175
2176func TestCommitSoftwareResponseDecode(t *testing.T) {
2177 // TODO: Need to complete implementation & debug this
2178 //goodMessage := ""
2179 //data, err := stringToPacket(goodMessage)
2180 //assert.NoError(t, err)
2181 //
2182 //packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2183 //assert.NotNil(t, packet)
2184 //
2185 //omciLayer := packet.Layer(LayerTypeOMCI)
2186 //assert.NotNil(t, packet)
2187 //
2188 //omciMsg, ok := omciLayer.(*OMCI)
2189 //assert.True(t, ok)
2190 //assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2191 //assert.Equal(t, omciMsg.MessageType, CommitSoftwareResponseType)
2192 //assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2193 //assert.Equal(t, omciMsg.Length, uint16(40))
2194 //
2195 //msgLayer := packet.Layer(LayerTypeCommitSoftwareResponse)
2196 //
2197 //assert.NotNil(t, msgLayer)
2198 //
2199 //response, ok2 := msgLayer.(*CommitSoftwareResponse)
2200 //assert.True(t, ok2)
2201 //assert.NotNil(t, response)
2202 //
2203 //// Verify string output for message
2204 //packetString := packet.String()
2205 //assert.NotZero(t, len(packetString))
2206}
2207
2208func TestCommitSoftwareResponseSerialize(t *testing.T) {
2209 // TODO: Need to complete implementation & debug this
2210 //goodMessage := ""
2211 //
2212 //omciLayer := &OMCI{
2213 // TransactionID: 0x01,
2214 // MessageType: CommitSoftwareResponseType,
2215 // // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2216 // // Length: 0x28, // Optional, defaults to 40 octets
2217 //}
2218 //request := &CommitSoftwareResponse{
2219 // MeBasePacket: MeBasePacket{
2220 // EntityClass: OnuDataClassID,
2221 // // Default Instance ID is 0
2222 // },
2223 //}
2224 //// Test serialization back to former string
2225 //var options gopacket.SerializeOptions
2226 //options.FixLengths = true
2227 //
2228 //buffer := gopacket.NewSerializeBuffer()
2229 //err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2230 //assert.NoError(t, err)
2231 //
2232 //outgoingPacket := buffer.Bytes()
2233 //reconstituted := packetToString(outgoingPacket)
2234 //assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2235}
2236
2237func TestMibResetResponseDecode(t *testing.T) {
2238 goodMessage := "00012F0A00020000000000000000000000000000000000000000000000000000000000000000000000000028"
2239 data, err := stringToPacket(goodMessage)
2240 assert.NoError(t, err)
2241
2242 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2243 assert.NotNil(t, packet)
2244
2245 omciLayer := packet.Layer(LayerTypeOMCI)
2246 assert.NotNil(t, packet)
2247
2248 omciMsg, ok := omciLayer.(*OMCI)
2249 assert.True(t, ok)
2250 assert.Equal(t, omciMsg.MessageType, MibResetResponseType)
2251 assert.Equal(t, omciMsg.Length, uint16(40))
2252
2253 msgLayer := packet.Layer(LayerTypeMibResetResponse)
2254
2255 assert.NotNil(t, msgLayer)
2256
2257 response, ok2 := msgLayer.(*MibResetResponse)
2258 assert.True(t, ok2)
2259 assert.NotNil(t, response)
2260
2261 // Verify string output for message
2262 packetString := packet.String()
2263 assert.NotZero(t, len(packetString))
2264}
2265
2266func TestMibResetResponseSerialize(t *testing.T) {
2267 goodMessage := "00012F0A00020000000000000000000000000000000000000000000000000000000000000000000000000028"
2268
2269 omciLayer := &OMCI{
2270 TransactionID: 0x01,
2271 MessageType: MibResetResponseType,
2272 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2273 // Length: 0x28, // Optional, defaults to 40 octets
2274 }
2275 request := &MibResetResponse{
2276 MeBasePacket: MeBasePacket{
2277 EntityClass: me.OnuDataClassID,
2278 // Default Instance ID is 0
2279 },
2280 }
2281 // Test serialization back to former string
2282 var options gopacket.SerializeOptions
2283 options.FixLengths = true
2284
2285 buffer := gopacket.NewSerializeBuffer()
2286 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2287 assert.NoError(t, err)
2288
2289 outgoingPacket := buffer.Bytes()
2290 reconstituted := packetToString(outgoingPacket)
2291 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2292}
2293
2294func TestSynchronizeTimeRequestDecode(t *testing.T) {
2295 goodMessage := "0109580a0100000007e20c0101301b0000000000000000000000000000000000000000000000000000000028"
2296 data, err := stringToPacket(goodMessage)
2297 assert.NoError(t, err)
2298
2299 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2300 assert.NotNil(t, packet)
2301
2302 omciLayer := packet.Layer(LayerTypeOMCI)
2303 assert.NotNil(t, packet)
2304
2305 omciMsg, ok := omciLayer.(*OMCI)
2306 assert.True(t, ok)
2307 assert.Equal(t, omciMsg.MessageType, SynchronizeTimeRequestType)
2308 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2309 assert.Equal(t, omciMsg.Length, uint16(40))
2310
2311 msgLayer := packet.Layer(LayerTypeSynchronizeTimeRequest)
2312 assert.NotNil(t, msgLayer)
2313
2314 request, ok2 := msgLayer.(*SynchronizeTimeRequest)
2315 assert.True(t, ok2)
2316 assert.NotNil(t, request)
2317 assert.Equal(t, request.Year, uint16(2018))
2318 assert.Equal(t, request.Month, uint8(12))
2319 assert.Equal(t, request.Day, uint8(1))
2320 assert.Equal(t, request.Hour, uint8(01))
2321 assert.Equal(t, request.Minute, uint8(48))
2322 assert.Equal(t, request.Second, uint8(27))
2323
2324 // Verify string output for message
2325 packetString := packet.String()
2326 assert.NotZero(t, len(packetString))
2327}
2328
2329func TestSynchronizeTimeRequestSerialize(t *testing.T) {
2330 goodMessage := "0109580a0100000007e20c0101301b0000000000000000000000000000000000000000000000000000000028"
2331
2332 omciLayer := &OMCI{
2333 TransactionID: 0x0109,
2334 MessageType: SynchronizeTimeRequestType,
2335 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2336 // Length: 0x28, // Optional, defaults to 40 octets
2337 }
2338 request := &SynchronizeTimeRequest{
2339 MeBasePacket: MeBasePacket{
2340 EntityClass: me.OnuGClassID,
2341 // Default Instance ID is 0
2342 },
2343 Year: uint16(2018),
2344 Month: uint8(12),
2345 Day: uint8(1),
2346 Hour: uint8(01),
2347 Minute: uint8(48),
2348 Second: uint8(27),
2349 }
2350 // Test serialization back to former string
2351 var options gopacket.SerializeOptions
2352 options.FixLengths = true
2353
2354 buffer := gopacket.NewSerializeBuffer()
2355 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2356 assert.NoError(t, err)
2357
2358 outgoingPacket := buffer.Bytes()
2359 reconstituted := packetToString(outgoingPacket)
2360 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2361}
2362
2363func TestSynchronizeTimeResponseDecode(t *testing.T) {
2364 goodMessage := "0109380a01000000000000000000000000000000000000000000000000000000000000000000000000000028"
2365 data, err := stringToPacket(goodMessage)
2366 assert.NoError(t, err)
2367
2368 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2369 assert.NotNil(t, packet)
2370
2371 omciLayer := packet.Layer(LayerTypeOMCI)
2372 assert.NotNil(t, packet)
2373
2374 omciMsg, ok := omciLayer.(*OMCI)
2375 assert.True(t, ok)
2376 assert.Equal(t, omciMsg.MessageType, SynchronizeTimeResponseType)
2377 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2378 assert.Equal(t, omciMsg.Length, uint16(40))
2379
2380 msgLayer := packet.Layer(LayerTypeSynchronizeTimeResponse)
2381 assert.NotNil(t, msgLayer)
2382
2383 response, ok2 := msgLayer.(*SynchronizeTimeResponse)
2384 assert.True(t, ok2)
2385 assert.NotNil(t, response)
2386
2387 // Verify string output for message
2388 packetString := packet.String()
2389 assert.NotZero(t, len(packetString))
2390}
2391
2392func TestSynchronizeTimeResponseSerialize(t *testing.T) {
2393 goodMessage := "0109380a01000000000000000000000000000000000000000000000000000000000000000000000000000028"
2394
2395 omciLayer := &OMCI{
2396 TransactionID: 0x0109,
2397 MessageType: SynchronizeTimeResponseType,
2398 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2399 // Length: 0x28, // Optional, defaults to 40 octets
2400 }
2401 request := &SynchronizeTimeResponse{
2402 MeBasePacket: MeBasePacket{
2403 EntityClass: me.OnuGClassID,
2404 EntityInstance: uint16(0),
2405 },
2406 Result: me.Success,
2407 SuccessResults: uint8(0),
2408 }
2409 // Test serialization back to former string
2410 var options gopacket.SerializeOptions
2411 options.FixLengths = true
2412
2413 buffer := gopacket.NewSerializeBuffer()
2414 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2415 assert.NoError(t, err)
2416
2417 outgoingPacket := buffer.Bytes()
2418 reconstituted := packetToString(outgoingPacket)
2419 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2420}
2421
2422func TestRebootRequestDecode(t *testing.T) {
2423 goodMessage := "0001590a01000000010000000000000000000000000000000000000000000000000000000000000000000028"
2424 data, err := stringToPacket(goodMessage)
2425 assert.NoError(t, err)
2426
2427 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2428 assert.NotNil(t, packet)
2429
2430 omciLayer := packet.Layer(LayerTypeOMCI)
2431 assert.NotNil(t, packet)
2432
2433 omciMsg, ok := omciLayer.(*OMCI)
2434 assert.True(t, ok)
2435 assert.Equal(t, omciMsg.TransactionID, uint16(0x0001))
2436 assert.Equal(t, omciMsg.MessageType, RebootRequestType)
2437 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2438 assert.Equal(t, omciMsg.Length, uint16(40))
2439
2440 msgLayer := packet.Layer(LayerTypeRebootRequest)
2441 assert.NotNil(t, msgLayer)
2442
2443 request, ok2 := msgLayer.(*RebootRequest)
2444 assert.True(t, ok2)
2445 assert.NotNil(t, request)
2446 assert.Equal(t, request.EntityClass, me.OnuGClassID)
2447 assert.Equal(t, request.EntityInstance, uint16(0))
2448 assert.Equal(t, request.RebootCondition, uint8(1))
2449
2450 // Verify string output for message
2451 packetString := packet.String()
2452 assert.NotZero(t, len(packetString))
2453}
2454
2455func TestRebootRequestSerialize(t *testing.T) {
2456 goodMessage := "0001590a01000000020000000000000000000000000000000000000000000000000000000000000000000028"
2457
2458 omciLayer := &OMCI{
2459 TransactionID: 0x0001,
2460 MessageType: RebootRequestType,
2461 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2462 // Length: 0x28, // Optional, defaults to 40 octets
2463 }
2464 request := &RebootRequest{
2465 MeBasePacket: MeBasePacket{
2466 EntityClass: me.OnuGClassID,
2467 // Default Instance ID is 0
2468 },
2469 RebootCondition: uint8(2),
2470 }
2471 // Test serialization back to former string
2472 var options gopacket.SerializeOptions
2473 options.FixLengths = true
2474
2475 buffer := gopacket.NewSerializeBuffer()
2476 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2477 assert.NoError(t, err)
2478
2479 outgoingPacket := buffer.Bytes()
2480 reconstituted := packetToString(outgoingPacket)
2481 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2482}
2483
2484func TestRebootResponseDecode(t *testing.T) {
2485 goodMessage := "023c390a01000000000000000000000000000000000000000000000000000000000000000000000000000028"
2486 data, err := stringToPacket(goodMessage)
2487 assert.NoError(t, err)
2488
2489 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2490 assert.NotNil(t, packet)
2491
2492 omciLayer := packet.Layer(LayerTypeOMCI)
2493 assert.NotNil(t, packet)
2494
2495 omciMsg, ok := omciLayer.(*OMCI)
2496 assert.True(t, ok)
2497 assert.Equal(t, omciMsg.TransactionID, uint16(0x023c))
2498 assert.Equal(t, omciMsg.MessageType, RebootResponseType)
2499 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2500 assert.Equal(t, omciMsg.Length, uint16(40))
2501
2502 msgLayer := packet.Layer(LayerTypeRebootResponse)
2503 assert.NotNil(t, msgLayer)
2504
2505 response, ok2 := msgLayer.(*RebootResponse)
2506 assert.True(t, ok2)
2507 assert.NotNil(t, response)
2508 assert.Equal(t, response.EntityClass, me.OnuGClassID)
2509 assert.Equal(t, response.EntityInstance, uint16(0))
2510 assert.Equal(t, response.Result, me.Success)
2511
2512 // Verify string output for message
2513 packetString := packet.String()
2514 assert.NotZero(t, len(packetString))
2515}
2516
2517func TestRebootResponseSerialize(t *testing.T) {
2518 goodMessage := "023c390a01000000060000000000000000000000000000000000000000000000000000000000000000000028"
2519
2520 omciLayer := &OMCI{
2521 TransactionID: 0x023c,
2522 MessageType: RebootResponseType,
2523 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2524 // Length: 0x28, // Optional, defaults to 40 octets
2525 }
2526 request := &RebootResponse{
2527 MeBasePacket: MeBasePacket{
2528 EntityClass: me.OnuGClassID,
2529 EntityInstance: uint16(0),
2530 },
2531 Result: me.DeviceBusy,
2532 }
2533 // Test serialization back to former string
2534 var options gopacket.SerializeOptions
2535 options.FixLengths = true
2536
2537 buffer := gopacket.NewSerializeBuffer()
2538 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2539 assert.NoError(t, err)
2540
2541 outgoingPacket := buffer.Bytes()
2542 reconstituted := packetToString(outgoingPacket)
2543 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2544}
2545
2546func TestGetNextRequestDecode(t *testing.T) {
2547 goodMessage := "285e5a0a00ab0202040000010000000000000000000000000000000000000000000000000000000000000028"
2548 data, err := stringToPacket(goodMessage)
2549 assert.NoError(t, err)
2550
2551 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2552 assert.NotNil(t, packet)
2553
2554 omciLayer := packet.Layer(LayerTypeOMCI)
2555 assert.NotNil(t, packet)
2556
2557 omciMsg, ok := omciLayer.(*OMCI)
2558 assert.True(t, ok)
2559 assert.Equal(t, omciMsg.TransactionID, uint16(0x285e))
2560 assert.Equal(t, omciMsg.MessageType, GetNextRequestType)
2561 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2562 assert.Equal(t, omciMsg.Length, uint16(40))
2563
2564 msgLayer := packet.Layer(LayerTypeGetNextRequest)
2565 assert.NotNil(t, msgLayer)
2566
2567 request, ok2 := msgLayer.(*GetNextRequest)
2568 assert.True(t, ok2)
2569 assert.NotNil(t, request)
2570 assert.Equal(t, request.EntityClass, me.ExtendedVlanTaggingOperationConfigurationDataClassID)
2571 assert.Equal(t, request.EntityInstance, uint16(0x0202))
2572 assert.Equal(t, request.AttributeMask, uint16(0x0400))
2573 assert.Equal(t, request.SequenceNumber, uint16(1))
2574
2575 // Verify string output for message
2576 packetString := packet.String()
2577 assert.NotZero(t, len(packetString))
2578}
2579
2580func TestGetNextRequestSerialize(t *testing.T) {
2581 goodMessage := "285e5a0a00ab0202040000010000000000000000000000000000000000000000000000000000000000000028"
2582
2583 omciLayer := &OMCI{
2584 TransactionID: 0x285e,
2585 MessageType: GetNextRequestType,
2586 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2587 // Length: 0x28, // Optional, defaults to 40 octets
2588 }
2589 request := &GetNextRequest{
2590 MeBasePacket: MeBasePacket{
2591 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
2592 EntityInstance: uint16(0x0202),
2593 },
2594 AttributeMask: uint16(0x0400),
2595 SequenceNumber: uint16(1),
2596 }
2597 // Test serialization back to former string
2598 var options gopacket.SerializeOptions
2599 options.FixLengths = true
2600
2601 buffer := gopacket.NewSerializeBuffer()
2602 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2603 assert.NoError(t, err)
2604
2605 outgoingPacket := buffer.Bytes()
2606 reconstituted := packetToString(outgoingPacket)
2607 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2608}
2609
2610func TestGetNextResponseDecode(t *testing.T) {
2611 goodMessage := "285e3a0a00ab0202000400080334000000000000000000000000000000000000000000000000000000000028"
2612
2613 data, err := stringToPacket(goodMessage)
2614 assert.NoError(t, err)
2615
2616 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2617 assert.NotNil(t, packet)
2618
2619 omciLayer := packet.Layer(LayerTypeOMCI)
2620 assert.NotNil(t, packet)
2621
2622 omciMsg, ok := omciLayer.(*OMCI)
2623 assert.True(t, ok)
2624 assert.Equal(t, omciMsg.TransactionID, uint16(0x285e))
2625 assert.Equal(t, omciMsg.MessageType, GetNextResponseType)
2626 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2627 assert.Equal(t, omciMsg.Length, uint16(40))
2628
2629 msgLayer := packet.Layer(LayerTypeGetNextResponse)
2630 assert.NotNil(t, msgLayer)
2631
2632 vlanOpTable := []byte{0x08, 0x03, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00,
2633 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
2634
2635 response, ok2 := msgLayer.(*GetNextResponse)
2636 assert.True(t, ok2)
2637 assert.NotNil(t, response)
2638 assert.Equal(t, me.ExtendedVlanTaggingOperationConfigurationDataClassID, response.EntityClass)
2639 assert.Equal(t, uint16(0x0202), response.EntityInstance)
2640 assert.Equal(t, me.Success, response.Result)
2641 assert.Equal(t, uint16(0x0400), response.AttributeMask)
2642
2643 // For GetNextResponse frames, caller is responsible for trimming last packet to remaining
2644 // size
2645 expectedOctets := 16
2646 value := response.Attributes["ReceivedFrameVlanTaggingOperationTable"]
2647 assert.Equal(t, vlanOpTable, value.([]byte)[:expectedOctets])
2648
2649 // Verify string output for message
2650 packetString := packet.String()
2651 assert.NotZero(t, len(packetString))
2652}
2653
2654func TestGetNextResponseSerialize(t *testing.T) {
2655 goodMessage := "285e3a0a00ab0202000400080334000000000000000000000000000000000000000000000000000000000028"
2656
2657 omciLayer := &OMCI{
2658 TransactionID: 0x285e,
2659 MessageType: GetNextResponseType,
2660 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2661 // Length: 0x28, // Optional, defaults to 40 octets
2662 }
2663 vlanOpTable := []byte{0x08, 0x03, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00,
2664 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
2665
2666 request := &GetNextResponse{
2667 MeBasePacket: MeBasePacket{
2668 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
2669 EntityInstance: uint16(0x0202),
2670 },
2671 Result: me.Success,
2672 AttributeMask: uint16(0x0400),
2673 Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": vlanOpTable},
2674 }
2675 // Test serialization back to former string
2676 var options gopacket.SerializeOptions
2677 options.FixLengths = true
2678
2679 buffer := gopacket.NewSerializeBuffer()
2680 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2681 assert.NoError(t, err)
2682
2683 outgoingPacket := buffer.Bytes()
2684 reconstituted := packetToString(outgoingPacket)
2685 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2686}
2687
2688// TODO: Create request/response tests for all of the following types//GetCurrentData,
2689//SetTable}
2690
2691func TestAlarmNotificationDecode(t *testing.T) {
2692 goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028"
2693 data, err := stringToPacket(goodMessage)
2694 assert.NoError(t, err)
2695
2696 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2697 assert.NotNil(t, packet)
2698
2699 omciLayer := packet.Layer(LayerTypeOMCI)
2700 assert.NotNil(t, packet)
2701
2702 omciMsg, ok := omciLayer.(*OMCI)
2703 assert.True(t, ok)
2704 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2705 assert.Equal(t, omciMsg.MessageType, AlarmNotificationType)
2706 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2707 assert.Equal(t, omciMsg.Length, uint16(40))
2708
2709 msgLayer := packet.Layer(LayerTypeAlarmNotification)
2710 assert.NotNil(t, msgLayer)
2711
2712 request, ok2 := msgLayer.(*AlarmNotificationMsg)
2713 assert.True(t, ok2)
2714 assert.NotNil(t, request)
2715 assert.Equal(t, request.EntityClass, me.PhysicalPathTerminationPointEthernetUniClassID)
2716 assert.Equal(t, request.EntityInstance, uint16(0x104))
2717 assert.Equal(t, request.AlarmBitmap, [28]byte{
2718 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2719 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2720 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2721 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2722 })
2723 assert.Equal(t, request.AlarmSequenceNumber, byte(5))
2724
Chip Boling34ebcb62021-02-02 12:13:58 -06002725 // Active/Clear tests
2726 active, err2 := request.IsAlarmActive(0)
2727 clear, err3 := request.IsAlarmClear(0)
2728 assert.Nil(t, err2)
2729 assert.Nil(t, err3)
2730 assert.True(t, active)
2731 assert.False(t, clear)
2732
2733 // Active/Clear for undefined alarm bits
2734 active, err2 = request.IsAlarmActive(1)
2735 clear, err3 = request.IsAlarmClear(1)
2736 assert.NotNil(t, err2)
2737 assert.NotNil(t, err3)
2738
Chip Boling6e27b352020-02-14 09:10:01 -06002739 // Verify string output for message
2740 packetString := packet.String()
2741 assert.NotZero(t, len(packetString))
2742}
2743
Chip Boling34ebcb62021-02-02 12:13:58 -06002744func TestInvalidClassAlarmNotificationDecode(t *testing.T) {
2745 // Choosing GalEthernetProfile (272) since it does not support alarms, show we should
2746 // file the decode
2747 badMessage := "0000100a01100104800000000000000000000000000000000000000000000000000000000000000500000028"
2748 data, err := stringToPacket(badMessage)
2749 assert.NoError(t, err)
2750
2751 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2752 assert.NotNil(t, packet)
2753
2754 omciLayer := packet.Layer(LayerTypeOMCI)
2755 assert.NotNil(t, packet)
2756
2757 omciMsg, ok := omciLayer.(*OMCI)
2758 assert.True(t, ok)
2759 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2760 assert.Equal(t, omciMsg.MessageType, AlarmNotificationType)
2761 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2762 assert.Equal(t, omciMsg.Length, uint16(40))
2763
2764 msgLayer := packet.Layer(LayerTypeAlarmNotification)
2765 assert.Nil(t, msgLayer)
2766
2767 request, ok2 := msgLayer.(*AlarmNotificationMsg)
2768 assert.False(t, ok2)
2769 assert.Nil(t, request)
2770}
2771
2772func TestUnknownsMeAlarmNotificationDecode(t *testing.T) {
2773 // Choosing class ID 22 since it is in the G.988 class ID space and is reserved
2774 goodMessage := "0000100a00160104800000000000000000000000000000000000000000000000000000000000000500000028"
2775 data, err := stringToPacket(goodMessage)
2776 assert.NoError(t, err)
2777
2778 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2779 assert.NotNil(t, packet)
2780
2781 omciLayer := packet.Layer(LayerTypeOMCI)
2782 assert.NotNil(t, packet)
2783
2784 omciMsg, ok := omciLayer.(*OMCI)
2785 assert.True(t, ok)
2786 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2787 assert.Equal(t, omciMsg.MessageType, AlarmNotificationType)
2788 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2789 assert.Equal(t, omciMsg.Length, uint16(40))
2790
2791 msgLayer := packet.Layer(LayerTypeAlarmNotification)
2792 assert.NotNil(t, msgLayer)
2793
2794 request, ok2 := msgLayer.(*AlarmNotificationMsg)
2795 assert.True(t, ok2)
2796 assert.NotNil(t, request)
2797 assert.Equal(t, request.EntityClass, me.ClassID(22))
2798 assert.Equal(t, request.EntityInstance, uint16(0x104))
2799 assert.Equal(t, request.AlarmBitmap, [28]byte{
2800 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2801 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2802 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2803 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2804 })
2805 assert.Equal(t, request.AlarmSequenceNumber, byte(5))
2806}
2807
2808func TestVendorSpecificAlarmNotificationDecode(t *testing.T) {
2809 // Choosing class ID 255 since it is in the first vendor specific class ID space
2810 goodMessage := "0000100a00FF0104800000000000000000000000000000000000000000000000000000000000000500000028"
2811 data, err := stringToPacket(goodMessage)
2812 assert.NoError(t, err)
2813
2814 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2815 assert.NotNil(t, packet)
2816
2817 omciLayer := packet.Layer(LayerTypeOMCI)
2818 assert.NotNil(t, packet)
2819
2820 omciMsg, ok := omciLayer.(*OMCI)
2821 assert.True(t, ok)
2822 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2823 assert.Equal(t, omciMsg.MessageType, AlarmNotificationType)
2824 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2825 assert.Equal(t, omciMsg.Length, uint16(40))
2826
2827 msgLayer := packet.Layer(LayerTypeAlarmNotification)
2828 assert.NotNil(t, msgLayer)
2829
2830 request, ok2 := msgLayer.(*AlarmNotificationMsg)
2831 assert.True(t, ok2)
2832 assert.NotNil(t, request)
2833 assert.Equal(t, request.EntityClass, me.ClassID(255))
2834 assert.Equal(t, request.EntityInstance, uint16(0x104))
2835 assert.Equal(t, request.AlarmBitmap, [28]byte{
2836 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2837 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2838 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2839 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2840 })
2841 assert.Equal(t, request.AlarmSequenceNumber, byte(5))
2842}
2843
Chip Boling6e27b352020-02-14 09:10:01 -06002844func TestAlarmNotificationSerialize(t *testing.T) {
2845 goodMessage := "0000100a000b0104800000000000000000000000000000000000000000000000000000000000000500000028"
2846
2847 omciLayer := &OMCI{
2848 TransactionID: 0,
2849 MessageType: AlarmNotificationType,
2850 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2851 // Length: 0x28, // Optional, defaults to 40 octets
2852 }
2853 request := &AlarmNotificationMsg{
2854 MeBasePacket: MeBasePacket{
2855 EntityClass: me.PhysicalPathTerminationPointEthernetUniClassID,
2856 EntityInstance: uint16(0x104),
2857 },
2858 AlarmBitmap: [28]byte{
2859 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2860 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2861 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2862 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2863 },
2864 AlarmSequenceNumber: byte(5),
2865 }
2866 // Test serialization back to former string
2867 var options gopacket.SerializeOptions
2868 options.FixLengths = true
2869
2870 buffer := gopacket.NewSerializeBuffer()
2871 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2872 assert.NoError(t, err)
2873
2874 outgoingPacket := buffer.Bytes()
2875 reconstituted := packetToString(outgoingPacket)
2876 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2877}
2878
2879func TestAttributeValueChangeDecode(t *testing.T) {
2880 goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028"
2881 data, err := stringToPacket(goodMessage)
2882 assert.NoError(t, err)
2883
2884 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2885 assert.NotNil(t, packet)
2886
2887 omciLayer := packet.Layer(LayerTypeOMCI)
2888 assert.NotNil(t, packet)
2889
2890 omciMsg, ok := omciLayer.(*OMCI)
2891 assert.True(t, ok)
2892 assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
2893 assert.Equal(t, omciMsg.MessageType, AttributeValueChangeType)
2894 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2895 assert.Equal(t, omciMsg.Length, uint16(40))
2896
2897 msgLayer := packet.Layer(LayerTypeAttributeValueChange)
2898 assert.NotNil(t, msgLayer)
2899
2900 request, ok2 := msgLayer.(*AttributeValueChangeMsg)
2901 assert.True(t, ok2)
2902 assert.NotNil(t, request)
2903 assert.Equal(t, request.AttributeMask, uint16(0x8000))
2904 assert.Equal(t, request.EntityClass, me.SoftwareImageClassID)
2905 assert.Equal(t, request.EntityInstance, uint16(0))
2906 assert.Equal(t, request.Attributes["Version"], []byte{
2907 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36,
2908 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
2909
2910 // Verify string output for message
2911 packetString := packet.String()
2912 assert.NotZero(t, len(packetString))
2913}
2914
2915func TestAttributeValueChangeSerialize(t *testing.T) {
2916 goodMessage := "0000110a0007000080004d4c2d33363236000000000000000000000000000000000000000000000000000028"
2917
2918 omciLayer := &OMCI{
2919 TransactionID: 0,
2920 MessageType: AttributeValueChangeType,
2921 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
2922 // Length: 0x28, // Optional, defaults to 40 octets
2923 }
2924 request := &AttributeValueChangeMsg{
2925 MeBasePacket: MeBasePacket{
2926 EntityClass: me.SoftwareImageClassID,
2927 EntityInstance: uint16(0),
2928 },
2929 AttributeMask: uint16(0x8000),
2930 Attributes: me.AttributeValueMap{
2931 "Version": []byte{
2932 0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36,
2933 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2934 },
2935 },
2936 }
2937 // Test serialization back to former string
2938 var options gopacket.SerializeOptions
2939 options.FixLengths = true
2940
2941 buffer := gopacket.NewSerializeBuffer()
2942 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
2943 assert.NoError(t, err)
2944
2945 outgoingPacket := buffer.Bytes()
2946 reconstituted := packetToString(outgoingPacket)
2947 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
2948}
2949
Chip Boling4e0ac9a2021-01-20 14:23:09 -06002950func TestJira3769(t *testing.T) {
2951 // VOL-3769. Error parsing get response with processing error and large mask
2952 sampleMessage := "035e290a0101000001FFFC000000000000000000000000000000000000000000000000000000000000000028"
2953 data, err := stringToPacket(sampleMessage)
2954 assert.NoError(t, err)
2955
2956 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
2957 assert.NotNil(t, packet)
2958
2959 omciLayer := packet.Layer(LayerTypeOMCI)
2960 assert.NotNil(t, omciLayer)
2961
2962 omciMsg, ok := omciLayer.(*OMCI)
2963 assert.True(t, ok)
2964 assert.Equal(t, omciMsg.TransactionID, uint16(0x035e))
2965 assert.Equal(t, omciMsg.MessageType, GetResponseType)
2966 assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
2967 assert.Equal(t, omciMsg.Length, uint16(40))
2968
2969 // before bugfix for this JIRA, the following call returned 'nil' Failure was
2970 // occuring before this at during getResposne decoding.
2971 msgLayer := packet.Layer(LayerTypeGetResponse)
2972 assert.NotNil(t, msgLayer)
2973
2974 response, ok2 := msgLayer.(*GetResponse)
2975 assert.True(t, ok2)
2976 assert.NotNil(t, response)
2977 assert.Equal(t, response.Result, me.ProcessingError)
2978 assert.Equal(t, response.AttributeMask, uint16(0xFFFC))
2979}
Chip Boling34ebcb62021-02-02 12:13:58 -06002980
Chip Boling6e27b352020-02-14 09:10:01 -06002981// TODO: Create notification tests for all of the following types
2982//TestResult,