blob: 4020fcec6798bd99ff821e681b2b2f10f85776db [file] [log] [blame]
Chip Boling610117d2021-09-09 11:24:34 -05001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
3 * Copyright 2020-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package omci_test
19
20import (
21 "github.com/google/gopacket"
Andrea Campanellae0cd8232021-10-15 15:10:23 +020022 . "github.com/opencord/omci-lib-go/v2"
23 me "github.com/opencord/omci-lib-go/v2/generated"
Chip Boling610117d2021-09-09 11:24:34 -050024 "github.com/stretchr/testify/assert"
25 "strings"
26 "testing"
27)
28
29func TestSetTableRequestDecode(t *testing.T) {
30 // Single row
31 row := "F0000000" + "F0000000" + "00000000" + "00000000"
32 goodMessage := "01075d0b00AB123400120400"
33 data, err := stringToPacket(goodMessage + row)
34 assert.NoError(t, err)
35
36 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
37 assert.NotNil(t, packet)
38
39 omciLayer := packet.Layer(LayerTypeOMCI)
40 assert.NotNil(t, omciLayer)
41
42 omciMsg, ok := omciLayer.(*OMCI)
43 assert.True(t, ok)
44 assert.NotNil(t, omciMsg)
45 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
46 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
47 assert.Equal(t, LayerTypeSetTableRequest, omciMsg.NextLayerType())
48 assert.Equal(t, uint16(0x0107), omciMsg.TransactionID)
49 assert.Equal(t, SetTableRequestType, omciMsg.MessageType)
50 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
51 assert.Equal(t, uint16(2+16), omciMsg.Length)
52
53 msgLayer := packet.Layer(LayerTypeSetTableRequest)
54 assert.NotNil(t, msgLayer)
55
56 request, ok2 := msgLayer.(*SetTableRequest)
57 assert.True(t, ok2)
58 assert.NotNil(t, request)
59 assert.Equal(t, LayerTypeSetTableRequest, request.LayerType())
60 assert.Equal(t, LayerTypeSetTableRequest, request.CanDecode())
61 assert.Equal(t, gopacket.LayerTypePayload, request.NextLayerType())
62
63 assert.Equal(t, me.ExtendedVlanTaggingOperationConfigurationDataClassID, request.EntityClass)
64 assert.Equal(t, uint16(0x1234), request.EntityInstance)
65 assert.Equal(t, uint16(0x0400), request.AttributeMask)
66
67 vlanTable, tblOk := request.Attributes["ReceivedFrameVlanTaggingOperationTable"]
68 assert.True(t, tblOk)
69 assert.NotNil(t, vlanTable)
70
71 rows, rowOk := vlanTable.(me.TableRows)
72 assert.True(t, rowOk)
73 assert.NotNil(t, rows)
74 assert.Equal(t, 1, rows.NumRows)
75 assert.Equal(t, 16*rows.NumRows, len(rows.Rows))
76
77 // Verify string output for message
78 packetString := packet.String()
79 assert.NotZero(t, len(packetString))
80}
81
82func TestSetTableRequestDecodeZeroRows(t *testing.T) {
83 // No rows are okay
84 row := ""
85 goodMessage := "01075d0b00AB123400020400"
86 data, err := stringToPacket(goodMessage + row)
87 assert.NoError(t, err)
88
89 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
90 assert.NotNil(t, packet)
91
92 omciLayer := packet.Layer(LayerTypeOMCI)
93 assert.NotNil(t, omciLayer)
94
95 omciMsg, ok := omciLayer.(*OMCI)
96 assert.True(t, ok)
97 assert.NotNil(t, omciMsg)
98 assert.Equal(t, uint16(2), omciMsg.Length)
99
100 msgLayer := packet.Layer(LayerTypeSetTableRequest)
101 assert.NotNil(t, msgLayer)
102
103 request, ok2 := msgLayer.(*SetTableRequest)
104 assert.True(t, ok2)
105 assert.NotNil(t, request)
106 assert.Equal(t, me.ExtendedVlanTaggingOperationConfigurationDataClassID, request.EntityClass)
107 assert.Equal(t, uint16(0x1234), request.EntityInstance)
108 assert.Equal(t, uint16(0x0400), request.AttributeMask)
109
110 vlanTable, tblOk := request.Attributes["ReceivedFrameVlanTaggingOperationTable"]
111 assert.True(t, tblOk)
112 assert.NotNil(t, vlanTable)
113
114 rows, rowOk := vlanTable.(me.TableRows)
115 assert.True(t, rowOk)
116 assert.NotNil(t, rows)
117 assert.Equal(t, 0, rows.NumRows)
118 assert.Nil(t, rows.Rows)
119
120 // Verify string output for message
121 packetString := packet.String()
122 assert.NotZero(t, len(packetString))
123}
124
125func TestSetTableRequestDecodeMultipleRows(t *testing.T) {
126 // More than one row
127 row1 := "F0000000" + "F0000000" + "00000000" + "00000000"
128 row2 := "70000000" + "F0000000" + "00000000" + "00000000"
129 row3 := "70000000" + "70000000" + "00000000" + "00000000"
130 goodMessage := "01075d0b00AB123400320400"
131 data, err := stringToPacket(goodMessage + row1 + row2 + row3)
132 assert.NoError(t, err)
133
134 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
135 assert.NotNil(t, packet)
136
137 omciLayer := packet.Layer(LayerTypeOMCI)
138 assert.NotNil(t, omciLayer)
139
140 omciMsg, ok := omciLayer.(*OMCI)
141 assert.True(t, ok)
142 assert.NotNil(t, omciMsg)
143 assert.Equal(t, uint16(2+(3*16)), omciMsg.Length)
144
145 msgLayer := packet.Layer(LayerTypeSetTableRequest)
146 assert.NotNil(t, msgLayer)
147
148 request, ok2 := msgLayer.(*SetTableRequest)
149 assert.True(t, ok2)
150 assert.NotNil(t, request)
151 vlanTable, tblOk := request.Attributes["ReceivedFrameVlanTaggingOperationTable"]
152 assert.True(t, tblOk)
153 assert.NotNil(t, vlanTable)
154
155 rows, rowOk := vlanTable.(me.TableRows)
156 assert.True(t, rowOk)
157 assert.NotNil(t, rows)
158 assert.Equal(t, 3, rows.NumRows)
159 assert.Equal(t, 16*rows.NumRows, len(rows.Rows))
160
161 // Verify string output for message
162 packetString := packet.String()
163 assert.NotZero(t, len(packetString))
164}
165
166func TestSetTableRequestDecodeTruncatedRow(t *testing.T) {
167 // More than one row, but one is short
168 row1 := "F0000000" + "F0000000" + "00000000" + "00000000"
169 row2 := "70000000" + "F0000000" + "00000000" + "00000000"
170 row3 := "70000000" + "70000000" + "00000000" + "0000"
171 goodMessage := "01075d0b00ab123400300400"
172 data, err := stringToPacket(goodMessage + row1 + row2 + row3)
173 assert.NoError(t, err)
174
175 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
176 assert.NotNil(t, packet)
177
178 omciLayer := packet.Layer(LayerTypeOMCI)
179 assert.NotNil(t, omciLayer)
180
181 omciMsg, ok := omciLayer.(*OMCI)
182 assert.True(t, ok)
183 assert.NotNil(t, omciMsg)
184 assert.Equal(t, uint16(48), omciMsg.Length)
185
186 msgLayer := packet.Layer(LayerTypeSetTableRequest)
187 assert.Nil(t, msgLayer)
188
189 shortLayer := packet.Layer(gopacket.LayerTypeDecodeFailure)
190 assert.NotNil(t, shortLayer)
191 assert.True(t, packet.Metadata().Truncated)
192}
193
194func TestSetTableRequestDecodeOneAttributeOnly(t *testing.T) {
195 // Single row but also extra non-table row
196 row := "F0000000" + "F0000000" + "00000000" + "00000000"
197 goodMessage := "01075d0b00ab123400138400" + "00"
198 data, err := stringToPacket(goodMessage + row)
199 assert.NoError(t, err)
200
201 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
202 assert.NotNil(t, packet)
203
204 omciLayer := packet.Layer(LayerTypeOMCI)
205 assert.NotNil(t, omciLayer)
206
207 omciMsg, ok := omciLayer.(*OMCI)
208 assert.True(t, ok)
209 assert.NotNil(t, omciMsg)
210 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
211 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
212 assert.Equal(t, LayerTypeSetTableRequest, omciMsg.NextLayerType())
213 assert.Equal(t, uint16(0x0107), omciMsg.TransactionID)
214 assert.Equal(t, SetTableRequestType, omciMsg.MessageType)
215 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
216 assert.Equal(t, uint16(3+16), omciMsg.Length)
217
218 msgLayer := packet.Layer(LayerTypeSetTableRequest)
219 assert.Nil(t, msgLayer)
220
221 badLayer := packet.Layer(gopacket.LayerTypeDecodeFailure)
222 assert.NotNil(t, badLayer)
223 assert.False(t, packet.Metadata().Truncated) // It was correct length, but not right
224
225 failure, ok3 := badLayer.(*gopacket.DecodeFailure)
226 assert.True(t, ok3)
227 assert.NotNil(t, failure)
228}
229
230func TestSetTableRequestDecodeTableAttributesOnly(t *testing.T) {
231
232 // Single row but also extra non-table row
233 goodMessage := "01075d0b00ab123400038000" + "00"
234 data, err := stringToPacket(goodMessage)
235 assert.NoError(t, err)
236
237 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
238 assert.NotNil(t, packet)
239
240 omciLayer := packet.Layer(LayerTypeOMCI)
241 assert.NotNil(t, omciLayer)
242
243 omciMsg, ok := omciLayer.(*OMCI)
244 assert.True(t, ok)
245 assert.NotNil(t, omciMsg)
246 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
247 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
248 assert.Equal(t, LayerTypeSetTableRequest, omciMsg.NextLayerType())
249 assert.Equal(t, uint16(0x0107), omciMsg.TransactionID)
250 assert.Equal(t, SetTableRequestType, omciMsg.MessageType)
251 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
252 assert.Equal(t, uint16(3), omciMsg.Length)
253
254 msgLayer := packet.Layer(LayerTypeSetTableRequest)
255 assert.Nil(t, msgLayer)
256
257 badLayer := packet.Layer(gopacket.LayerTypeDecodeFailure)
258 assert.NotNil(t, badLayer)
259 assert.False(t, packet.Metadata().Truncated) // It was correct length, but not right
260
261 failure, ok3 := badLayer.(*gopacket.DecodeFailure)
262 assert.True(t, ok3)
263 assert.NotNil(t, failure)
264}
265
266func TestSetTableRequestDecodeMeNotSupported(t *testing.T) {
267
268 // Single row but also extra non-table row
269 goodMessage := "01075d0b0100000000031000" + "01"
270 data, err := stringToPacket(goodMessage)
271 assert.NoError(t, err)
272
273 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
274 assert.NotNil(t, packet)
275
276 omciLayer := packet.Layer(LayerTypeOMCI)
277 assert.NotNil(t, omciLayer)
278
279 omciMsg, ok := omciLayer.(*OMCI)
280 assert.True(t, ok)
281 assert.NotNil(t, omciMsg)
282 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
283 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
284 assert.Equal(t, LayerTypeSetTableRequest, omciMsg.NextLayerType())
285 assert.Equal(t, uint16(0x0107), omciMsg.TransactionID)
286 assert.Equal(t, SetTableRequestType, omciMsg.MessageType)
287 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
288 assert.Equal(t, uint16(3), omciMsg.Length)
289
290 msgLayer := packet.Layer(LayerTypeSetTableRequest)
291 assert.Nil(t, msgLayer)
292
293 badLayer := packet.Layer(gopacket.LayerTypeDecodeFailure)
294 assert.NotNil(t, badLayer)
295 assert.False(t, packet.Metadata().Truncated) // It was correct length, but not right
296
297 failure, ok3 := badLayer.(*gopacket.DecodeFailure)
298 assert.True(t, ok3)
299 assert.NotNil(t, failure)
300}
301
302func TestSetTableRequestDecodeTableWritableOnly(t *testing.T) {
303
304 // Single row but also extra non-table row
305 goodMessage := "01075d0b00ab123400044000" + "0000"
306 data, err := stringToPacket(goodMessage)
307 assert.NoError(t, err)
308
309 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
310 assert.NotNil(t, packet)
311
312 omciLayer := packet.Layer(LayerTypeOMCI)
313 assert.NotNil(t, omciLayer)
314
315 omciMsg, ok := omciLayer.(*OMCI)
316 assert.True(t, ok)
317 assert.NotNil(t, omciMsg)
318 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
319 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
320 assert.Equal(t, LayerTypeSetTableRequest, omciMsg.NextLayerType())
321 assert.Equal(t, uint16(0x0107), omciMsg.TransactionID)
322 assert.Equal(t, SetTableRequestType, omciMsg.MessageType)
323 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
324 assert.Equal(t, uint16(4), omciMsg.Length)
325
326 msgLayer := packet.Layer(LayerTypeSetTableRequest)
327 assert.Nil(t, msgLayer)
328
329 badLayer := packet.Layer(gopacket.LayerTypeDecodeFailure)
330 assert.NotNil(t, badLayer)
331 assert.False(t, packet.Metadata().Truncated) // It was correct length, but not right
332
333 failure, ok3 := badLayer.(*gopacket.DecodeFailure)
334 assert.True(t, ok3)
335 assert.NotNil(t, failure)
336}
337
338func TestSetTableRequestDecodeBaselineNotSupported(t *testing.T) {
339 // Single row
340 message := "01075d0a00AB1234001204000000000000000000000000000000000000000000000000000000000000000028"
341 data, err := stringToPacket(message)
342 assert.NoError(t, err)
343
344 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
345 assert.NotNil(t, packet)
346
347 omciLayer := packet.Layer(LayerTypeOMCI)
348 assert.NotNil(t, omciLayer)
349
350 omciMsg, ok := omciLayer.(*OMCI)
351 assert.True(t, ok)
352 assert.NotNil(t, omciMsg)
353 assert.Equal(t, uint16(0x0107), omciMsg.TransactionID)
354 assert.Equal(t, SetTableRequestType, omciMsg.MessageType)
355
356 msgLayer := packet.Layer(LayerTypeSetTableRequest)
357 assert.Nil(t, msgLayer)
358
359 badLayer := packet.Layer(gopacket.LayerTypeDecodeFailure)
360 assert.NotNil(t, badLayer)
361 assert.False(t, packet.Metadata().Truncated)
362}
363
364func TestSetTableRequestSerialize(t *testing.T) {
365 // Single row
366 row := "F0000001" + "F0000002" + "00000003" + "00000004"
367 goodMessage := "01075d0b00AB123400120400" + row
368
369 rowData, rErr := stringToPacket(row)
370 assert.NoError(t, rErr)
371
372 omciLayer := &OMCI{
373 TransactionID: 0x0107,
374 MessageType: SetTableRequestType,
375 DeviceIdentifier: ExtendedIdent,
376 }
377 tableRow := me.TableRows{
378 NumRows: 1,
379 Rows: rowData,
380 }
381 request := &SetTableRequest{
382 MeBasePacket: MeBasePacket{
383 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
384 EntityInstance: uint16(0x1234),
385 Extended: true,
386 },
387 AttributeMask: uint16(0x0400),
388 Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": tableRow},
389 }
390 // Test serialization back to former string
391 var options gopacket.SerializeOptions
392 options.FixLengths = true
393
394 buffer := gopacket.NewSerializeBuffer()
395 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
396 assert.NoError(t, err)
397
398 outgoingPacket := buffer.Bytes()
399 reconstituted := packetToString(outgoingPacket)
400 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
401}
402
403func TestSetTableRequestZeroTICSerialize(t *testing.T) {
404 // Single row
405 row := "F0000001" + "F0000002" + "00000003" + "00000004"
406 rowData, rErr := stringToPacket(row)
407 assert.NoError(t, rErr)
408
409 omciLayer := &OMCI{
410 TransactionID: 0x0,
411 MessageType: SetTableRequestType,
412 DeviceIdentifier: ExtendedIdent,
413 }
414 tableRow := me.TableRows{
415 NumRows: 1,
416 Rows: rowData,
417 }
418 request := &SetTableRequest{
419 MeBasePacket: MeBasePacket{
420 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
421 EntityInstance: uint16(0x1234),
422 Extended: true,
423 },
424 AttributeMask: uint16(0x0400),
425 Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": tableRow},
426 }
427 // Test serialization back to former string
428 var options gopacket.SerializeOptions
429 options.FixLengths = true
430
431 buffer := gopacket.NewSerializeBuffer()
432 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
433 assert.Error(t, err)
434}
435
436func TestSetTableRequestSerializeZeroRows(t *testing.T) {
437 // No rows is sort of dumb on a set but technically it is allowed
438 goodMessage := "01075d0b00AB123400020400"
439
440 omciLayer := &OMCI{
441 TransactionID: 0x0107,
442 MessageType: SetTableRequestType,
443 DeviceIdentifier: ExtendedIdent,
444 }
445 tableRow := me.TableRows{}
446 request := &SetTableRequest{
447 MeBasePacket: MeBasePacket{
448 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
449 EntityInstance: uint16(0x1234),
450 Extended: true,
451 },
452 AttributeMask: uint16(0x0400),
453 Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": tableRow},
454 }
455 // Test serialization back to former string
456 var options gopacket.SerializeOptions
457 options.FixLengths = true
458
459 buffer := gopacket.NewSerializeBuffer()
460 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
461 assert.NoError(t, err)
462
463 outgoingPacket := buffer.Bytes()
464 reconstituted := packetToString(outgoingPacket)
465 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
466}
467
468func TestSetTableRequestSerializeMultipleRows(t *testing.T) {
469 // More than one row
470 row1 := "F0000000" + "F0000000" + "00004000" + "0000000c"
471 row2 := "70000000" + "F0000000" + "00300000" + "0000000a"
472 row3 := "70000000" + "70000000" + "0005000b" + "0000000b"
473 goodMessage := "01075d0b00AB123400320400" + row1 + row2 + row3
474
475 rowData, rErr := stringToPacket(row1 + row2 + row3)
476 assert.NoError(t, rErr)
477
478 omciLayer := &OMCI{
479 TransactionID: 0x0107,
480 MessageType: SetTableRequestType,
481 DeviceIdentifier: ExtendedIdent,
482 }
483 tableRow := me.TableRows{
484 NumRows: 3,
485 Rows: rowData,
486 }
487 request := &SetTableRequest{
488 MeBasePacket: MeBasePacket{
489 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
490 EntityInstance: uint16(0x1234),
491 Extended: true,
492 },
493 AttributeMask: uint16(0x0400),
494 Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": tableRow},
495 }
496 // Test serialization back to former string
497 var options gopacket.SerializeOptions
498 options.FixLengths = true
499
500 buffer := gopacket.NewSerializeBuffer()
501 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
502 assert.NoError(t, err)
503
504 outgoingPacket := buffer.Bytes()
505 reconstituted := packetToString(outgoingPacket)
506 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
507}
508
509func TestSetTableRequestSerializeTruncatedRow(t *testing.T) {
510 // More than one row, but one is short
511 row1 := "F0000000" + "F0000000" + "00000000" + "00000000"
512 row2 := "70000000" + "F0000000" + "00000000" + "00000000"
513 row3 := "70000000" + "70000000" + "00000000" + "0000"
514
515 rowData, rErr := stringToPacket(row1 + row2 + row3)
516 assert.NoError(t, rErr)
517
518 omciLayer := &OMCI{
519 TransactionID: 0x0107,
520 MessageType: SetTableRequestType,
521 DeviceIdentifier: ExtendedIdent,
522 }
523 tableRow := me.TableRows{
524 NumRows: 3,
525 Rows: rowData,
526 }
527 request := &SetTableRequest{
528 MeBasePacket: MeBasePacket{
529 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
530 EntityInstance: uint16(0x1234),
531 Extended: true,
532 },
533 AttributeMask: uint16(0x0400),
534 Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": tableRow},
535 }
536 // Test serialization back to former string
537 var options gopacket.SerializeOptions
538 options.FixLengths = true
539
540 buffer := gopacket.NewSerializeBuffer()
541 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
542 assert.Error(t, err)
543}
544
545func TestSetTableRequestSerializeOneAttributeOnly(t *testing.T) {
546 rowData, rErr := stringToPacket("F0000000" + "F0000000" + "00000000" + "00000000")
547 assert.NoError(t, rErr)
548
549 omciLayer := &OMCI{
550 TransactionID: 0x0107,
551 MessageType: SetTableRequestType,
552 DeviceIdentifier: ExtendedIdent,
553 }
554 tableRow := me.TableRows{
555 NumRows: 1,
556 Rows: rowData,
557 }
558 request := &SetTableRequest{
559 MeBasePacket: MeBasePacket{
560 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
561 EntityInstance: uint16(0x1234),
562 Extended: true,
563 },
564 AttributeMask: uint16(0x8400),
565 Attributes: me.AttributeValueMap{
566 "ReceivedFrameVlanTaggingOperationTable": tableRow,
567 "AssociationType": byte(1),
568 },
569 }
570 // Test serialization back to former string
571 var options gopacket.SerializeOptions
572 options.FixLengths = true
573
574 buffer := gopacket.NewSerializeBuffer()
575 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
576 assert.Error(t, err)
577}
578
579func TestSetTableRequestSerializeTableAttributesOnly(t *testing.T) {
580 omciLayer := &OMCI{
581 TransactionID: 0x0107,
582 MessageType: SetTableRequestType,
583 DeviceIdentifier: ExtendedIdent,
584 }
585 request := &SetTableRequest{
586 MeBasePacket: MeBasePacket{
587 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
588 EntityInstance: uint16(0x1234),
589 Extended: true,
590 },
591 AttributeMask: uint16(0x8000),
592 Attributes: me.AttributeValueMap{
593 "AssociationType": byte(1),
594 },
595 }
596 // Test serialization back to former string
597 var options gopacket.SerializeOptions
598 options.FixLengths = true
599
600 buffer := gopacket.NewSerializeBuffer()
601 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
602 assert.Error(t, err)
603}
604
605func TestSetTableRequestSerializeTableWritableOnly(t *testing.T) {
606 omciLayer := &OMCI{
607 TransactionID: 0x0107,
608 MessageType: SetTableRequestType,
609 DeviceIdentifier: ExtendedIdent,
610 }
611 request := &SetTableRequest{
612 MeBasePacket: MeBasePacket{
613 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
614 EntityInstance: uint16(0x1234),
615 Extended: true,
616 },
617 AttributeMask: uint16(0x4000),
618 Attributes: me.AttributeValueMap{
619 "ReceivedFrameVlanTaggingOperationTableMaxSize": byte(1),
620 },
621 }
622 // Test serialization back to former string
623 var options gopacket.SerializeOptions
624 options.FixLengths = true
625
626 buffer := gopacket.NewSerializeBuffer()
627 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
628 assert.Error(t, err)
629}
630
631func TestSetTableRequestSerializeBaselineNotSupported(t *testing.T) {
632 omciLayer := &OMCI{
633 TransactionID: 0x0107,
634 MessageType: SetTableRequestType,
635 DeviceIdentifier: BaselineIdent,
636 }
637 tableRow := me.TableRows{}
638 request := &SetTableRequest{
639 MeBasePacket: MeBasePacket{
640 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
641 EntityInstance: uint16(0x1234),
642 Extended: false,
643 },
644 AttributeMask: uint16(0x0400),
645 Attributes: me.AttributeValueMap{"ReceivedFrameVlanTaggingOperationTable": tableRow},
646 }
647 // Test serialization back to former string
648 var options gopacket.SerializeOptions
649 options.FixLengths = true
650
651 buffer := gopacket.NewSerializeBuffer()
652 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
653 assert.Error(t, err)
654}
655
656func TestSetTableRequestSerializeBaselineManageEntityNotSupported(t *testing.T) {
657 omciLayer := &OMCI{
658 TransactionID: 0x0107,
659 MessageType: SetTableRequestType,
660 DeviceIdentifier: ExtendedIdent,
661 }
662 request := &SetTableRequest{
663 MeBasePacket: MeBasePacket{
664 EntityClass: me.OnuGClassID,
665 EntityInstance: uint16(0x0),
666 Extended: true,
667 },
668 AttributeMask: uint16(0x1000),
669 Attributes: me.AttributeValueMap{"TrafficManagementOption": byte(1)},
670 }
671 // Test serialization back to former string
672 var options gopacket.SerializeOptions
673 options.FixLengths = true
674
675 buffer := gopacket.NewSerializeBuffer()
676 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
677 assert.Error(t, err)
678}
679
680func TestSetTableResponseDecode(t *testing.T) {
681 goodMessage := "01073d0b00ab1234000101"
682 data, err := stringToPacket(goodMessage)
683 assert.NoError(t, err)
684
685 packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
686 assert.NotNil(t, packet)
687
688 omciLayer := packet.Layer(LayerTypeOMCI)
689 assert.NotNil(t, omciLayer)
690
691 omciMsg, ok := omciLayer.(*OMCI)
692 assert.True(t, ok)
693 assert.NotNil(t, omciMsg)
694 assert.Equal(t, LayerTypeOMCI, omciMsg.LayerType())
695 assert.Equal(t, LayerTypeOMCI, omciMsg.CanDecode())
696 assert.Equal(t, LayerTypeSetTableResponse, omciMsg.NextLayerType())
697 assert.Equal(t, uint16(0x0107), omciMsg.TransactionID)
698 assert.Equal(t, SetTableResponseType, omciMsg.MessageType)
699 assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
700 assert.Equal(t, uint16(1), omciMsg.Length)
701
702 msgLayer := packet.Layer(LayerTypeSetTableResponse)
703 assert.NotNil(t, msgLayer)
704
705 response, ok2 := msgLayer.(*SetTableResponse)
706 assert.True(t, ok2)
707 assert.NotNil(t, response)
708 assert.Equal(t, LayerTypeSetTableResponse, response.LayerType())
709 assert.Equal(t, LayerTypeSetTableResponse, response.CanDecode())
710 assert.Equal(t, gopacket.LayerTypePayload, response.NextLayerType())
711 assert.Equal(t, me.ProcessingError, response.Result)
712 assert.Equal(t, me.ExtendedVlanTaggingOperationConfigurationDataClassID, response.EntityClass)
713 assert.Equal(t, uint16(0x1234), response.EntityInstance)
714
715 // Verify string output for message
716 packetString := packet.String()
717 assert.NotZero(t, len(packetString))
718}
719
720func TestSetTableResponseSerialize(t *testing.T) {
721 goodMessage := "01073d0b00ab1234000103"
722
723 omciLayer := &OMCI{
724 TransactionID: 0x0107,
725 MessageType: SetTableResponseType,
726 DeviceIdentifier: ExtendedIdent,
727 }
728 request := &SetTableResponse{
729 MeBasePacket: MeBasePacket{
730 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
731 EntityInstance: uint16(0x1234),
732 Extended: true,
733 },
734 Result: me.ParameterError,
735 }
736 // Test serialization back to former string
737 var options gopacket.SerializeOptions
738 options.FixLengths = true
739
740 buffer := gopacket.NewSerializeBuffer()
741 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
742 assert.NoError(t, err)
743
744 outgoingPacket := buffer.Bytes()
745 reconstituted := packetToString(outgoingPacket)
746 assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
747}
748
749func TestSetTableResponseZeroTICSerialize(t *testing.T) {
750 omciLayer := &OMCI{
751 TransactionID: 0x0,
752 MessageType: SetTableResponseType,
753 DeviceIdentifier: ExtendedIdent,
754 }
755 request := &SetTableResponse{
756 MeBasePacket: MeBasePacket{
757 EntityClass: me.ExtendedVlanTaggingOperationConfigurationDataClassID,
758 EntityInstance: uint16(0x1234),
759 Extended: true,
760 },
761 Result: me.ParameterError,
762 }
763 // Test serialization back to former string
764 var options gopacket.SerializeOptions
765 options.FixLengths = true
766
767 buffer := gopacket.NewSerializeBuffer()
768 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
769 assert.Error(t, err)
770}