blob: 618c81a394e04e0eb434808be8a6f5b3dd2d0c02 [file] [log] [blame]
Takahiro Suzukid7bf8202020-12-17 20:21:59 +09001/*
2 * Copyright 2020-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package l2oam
17
18import (
19 "encoding/binary"
20 "encoding/hex"
21 "fmt"
22 "reflect"
23 "testing"
24
25 "github.com/google/gopacket"
26 "github.com/google/gopacket/layers"
27)
28
29func TestGenerateDiscoverySOLICIT(t *testing.T) {
30 tests := []struct {
31 name string
32 want gopacket.SerializableLayer
33 }{
34 // TODO: Add test cases.
35 {
36 name: "GenerateDiscoverySOLICIT-1",
37 want: &DiscoverySolicit{
38 // IEEE 1904.2
39 Opcode: 0xfd,
40 DiscoveryType: 0x01,
41 // Vendor-specific
42 VendorType: 0xfe,
43 Length: 37,
44 // Vendor ID
45 VendorIDType: 0xfd,
46 VendorIDLength: 3,
47 VendorID: []byte{0x2a, 0xea, 0x15},
48 // Controller Priority
49 CPType: 0x05,
50 CPLength: 1,
51 CPValue: []byte{128},
52 //NetworkID
53 NWType: 0x06,
54 NWLength: 16,
55 NWValue: []byte("tibitcom.com"),
56 //Device Type
57 DVType: 0x07,
58 DVLength: 1,
59 DVValue: []byte{1},
60 //Supported CLient Protocols
61 SCPType: 0x08,
62 SCPLength: 1,
63 SCPValue: []byte{0x03},
64 //Padding
65 PadType: 0xff,
66 PadLength: 1,
67 PadValue: []byte{0},
68 },
69 },
70 }
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 if got := GenerateDiscoverySOLICIT(); !reflect.DeepEqual(got, tt.want) {
74 t.Errorf("GenerateDiscoverySOLICIT() = %v, want %v", got, tt.want)
75 }
76 })
77 }
78}
79
80func TestDiscoverySolicit_String(t *testing.T) {
81 type fields struct {
82 BaseLayer layers.BaseLayer
83 Opcode uint8
84 DiscoveryType uint8
85 VendorType uint8
86 Length uint16
87 VendorIDType uint8
88 VendorIDLength uint16
89 VendorID []byte
90 CPType uint8
91 CPLength uint16
92 CPValue []byte
93 NWType uint8
94 NWLength uint16
95 NWValue []byte
96 DVType uint8
97 DVLength uint16
98 DVValue []byte
99 SCPType uint8
100 SCPLength uint16
101 SCPValue []byte
102 PadType uint8
103 PadLength uint16
104 PadValue []byte
105 }
106 tests := []struct {
107 name string
108 fields fields
109 want string
110 }{
111 // TODO: Add test cases.
112 {
113 name: "String-1",
114 fields: fields{
115 // IEEE 1904.2
116 Opcode: 0xfd,
117 DiscoveryType: 0x01,
118 // Vendor-specific
119 VendorType: 0xfe,
120 Length: 37,
121 // Vendor ID
122 VendorIDType: 0xfd,
123 VendorIDLength: 3,
124 VendorID: []byte{0x2a, 0xea, 0x15},
125 // Controller Priority
126 CPType: 0x05,
127 CPLength: 1,
128 CPValue: []byte{128},
129 //NetworkID
130 NWType: 0x06,
131 NWLength: 16,
132 NWValue: []byte("tibitcom.com"),
133 //Device Type
134 DVType: 0x07,
135 DVLength: 1,
136 DVValue: []byte{1},
137 //Supported CLient Protocols
138 SCPType: 0x08,
139 SCPLength: 1,
140 SCPValue: []byte{0x03},
141 //Padding
142 PadType: 0xff,
143 PadLength: 1,
144 PadValue: []byte{0},
145 },
146 want: fmt.Sprintf("Opcode:253, DiscoveryType:1, VendorType:254, Length:37, VendorIDType:253, VendorIDLength:3, VendorID:2aea15, CPType:5, CPLength:1, CPValue:80, NWType:6, NWLength:16, NWValue:%v, DVType:7, DVLength:1, DVValue:01, SCPType:8, SCPLength:1, SCPValue:03", hex.EncodeToString([]byte("tibitcom.com"))),
147 },
148 }
149 for _, tt := range tests {
150 t.Run(tt.name, func(t *testing.T) {
151 d := &DiscoverySolicit{
152 BaseLayer: tt.fields.BaseLayer,
153 Opcode: tt.fields.Opcode,
154 DiscoveryType: tt.fields.DiscoveryType,
155 VendorType: tt.fields.VendorType,
156 Length: tt.fields.Length,
157 VendorIDType: tt.fields.VendorIDType,
158 VendorIDLength: tt.fields.VendorIDLength,
159 VendorID: tt.fields.VendorID,
160 CPType: tt.fields.CPType,
161 CPLength: tt.fields.CPLength,
162 CPValue: tt.fields.CPValue,
163 NWType: tt.fields.NWType,
164 NWLength: tt.fields.NWLength,
165 NWValue: tt.fields.NWValue,
166 DVType: tt.fields.DVType,
167 DVLength: tt.fields.DVLength,
168 DVValue: tt.fields.DVValue,
169 SCPType: tt.fields.SCPType,
170 SCPLength: tt.fields.SCPLength,
171 SCPValue: tt.fields.SCPValue,
172 PadType: tt.fields.PadType,
173 PadLength: tt.fields.PadLength,
174 PadValue: tt.fields.PadValue,
175 }
176 if got := d.String(); got != tt.want {
177 t.Errorf("DiscoverySolicit.String() = %v, want %v", got, tt.want)
178 }
179 })
180 }
181}
182
183func TestDiscoverySolicit_Len(t *testing.T) {
184 type fields struct {
185 BaseLayer layers.BaseLayer
186 Opcode uint8
187 DiscoveryType uint8
188 VendorType uint8
189 Length uint16
190 VendorIDType uint8
191 VendorIDLength uint16
192 VendorID []byte
193 CPType uint8
194 CPLength uint16
195 CPValue []byte
196 NWType uint8
197 NWLength uint16
198 NWValue []byte
199 DVType uint8
200 DVLength uint16
201 DVValue []byte
202 SCPType uint8
203 SCPLength uint16
204 SCPValue []byte
205 PadType uint8
206 PadLength uint16
207 PadValue []byte
208 }
209 tests := []struct {
210 name string
211 fields fields
212 want int
213 }{
214 // TODO: Add test cases.
215 {
216 name: "Len-1",
217 fields: fields{
218 // IEEE 1904.2
219 Opcode: 0xfd,
220 DiscoveryType: 0x01,
221 // Vendor-specific
222 VendorType: 0xfe,
223 Length: 37,
224 // Vendor ID
225 VendorIDType: 0xfd,
226 VendorIDLength: 3,
227 VendorID: []byte{0x2a, 0xea, 0x15},
228 // Controller Priority
229 CPType: 0x05,
230 CPLength: 1,
231 CPValue: []byte{128},
232 //NetworkID
233 NWType: 0x06,
234 NWLength: 16,
235 NWValue: []byte("tibitcom.com"),
236 //Device Type
237 DVType: 0x07,
238 DVLength: 1,
239 DVValue: []byte{1},
240 //Supported CLient Protocols
241 SCPType: 0x08,
242 SCPLength: 1,
243 SCPValue: []byte{0x03},
244 //Padding
245 PadType: 0xff,
246 PadLength: 1,
247 PadValue: []byte{0},
248 },
249 want: 46,
250 },
251 }
252 for _, tt := range tests {
253 t.Run(tt.name, func(t *testing.T) {
254 d := &DiscoverySolicit{
255 BaseLayer: tt.fields.BaseLayer,
256 Opcode: tt.fields.Opcode,
257 DiscoveryType: tt.fields.DiscoveryType,
258 VendorType: tt.fields.VendorType,
259 Length: tt.fields.Length,
260 VendorIDType: tt.fields.VendorIDType,
261 VendorIDLength: tt.fields.VendorIDLength,
262 VendorID: tt.fields.VendorID,
263 CPType: tt.fields.CPType,
264 CPLength: tt.fields.CPLength,
265 CPValue: tt.fields.CPValue,
266 NWType: tt.fields.NWType,
267 NWLength: tt.fields.NWLength,
268 NWValue: tt.fields.NWValue,
269 DVType: tt.fields.DVType,
270 DVLength: tt.fields.DVLength,
271 DVValue: tt.fields.DVValue,
272 SCPType: tt.fields.SCPType,
273 SCPLength: tt.fields.SCPLength,
274 SCPValue: tt.fields.SCPValue,
275 PadType: tt.fields.PadType,
276 PadLength: tt.fields.PadLength,
277 PadValue: tt.fields.PadValue,
278 }
279 if got := d.Len(); got != tt.want {
280 t.Errorf("DiscoverySolicit.Len() = %v, want %v", got, tt.want)
281 }
282 })
283 }
284}
285
286func TestDiscoverySolicit_LayerType(t *testing.T) {
287 type fields struct {
288 BaseLayer layers.BaseLayer
289 Opcode uint8
290 DiscoveryType uint8
291 VendorType uint8
292 Length uint16
293 VendorIDType uint8
294 VendorIDLength uint16
295 VendorID []byte
296 CPType uint8
297 CPLength uint16
298 CPValue []byte
299 NWType uint8
300 NWLength uint16
301 NWValue []byte
302 DVType uint8
303 DVLength uint16
304 DVValue []byte
305 SCPType uint8
306 SCPLength uint16
307 SCPValue []byte
308 PadType uint8
309 PadLength uint16
310 PadValue []byte
311 }
312 tests := []struct {
313 name string
314 fields fields
315 want gopacket.LayerType
316 }{
317 // TODO: Add test cases.
318 {
319 name: "LayerType-1",
320 want: layers.LayerTypeEthernet,
321 },
322 }
323 for _, tt := range tests {
324 t.Run(tt.name, func(t *testing.T) {
325 d := &DiscoverySolicit{
326 BaseLayer: tt.fields.BaseLayer,
327 Opcode: tt.fields.Opcode,
328 DiscoveryType: tt.fields.DiscoveryType,
329 VendorType: tt.fields.VendorType,
330 Length: tt.fields.Length,
331 VendorIDType: tt.fields.VendorIDType,
332 VendorIDLength: tt.fields.VendorIDLength,
333 VendorID: tt.fields.VendorID,
334 CPType: tt.fields.CPType,
335 CPLength: tt.fields.CPLength,
336 CPValue: tt.fields.CPValue,
337 NWType: tt.fields.NWType,
338 NWLength: tt.fields.NWLength,
339 NWValue: tt.fields.NWValue,
340 DVType: tt.fields.DVType,
341 DVLength: tt.fields.DVLength,
342 DVValue: tt.fields.DVValue,
343 SCPType: tt.fields.SCPType,
344 SCPLength: tt.fields.SCPLength,
345 SCPValue: tt.fields.SCPValue,
346 PadType: tt.fields.PadType,
347 PadLength: tt.fields.PadLength,
348 PadValue: tt.fields.PadValue,
349 }
350 if got := d.LayerType(); !reflect.DeepEqual(got, tt.want) {
351 t.Errorf("DiscoverySolicit.LayerType() = %v, want %v", got, tt.want)
352 }
353 })
354 }
355}
356
357func TestDiscoverySolicit_SerializeTo(t *testing.T) {
358 type fields struct {
359 BaseLayer layers.BaseLayer
360 Opcode uint8
361 DiscoveryType uint8
362 VendorType uint8
363 Length uint16
364 VendorIDType uint8
365 VendorIDLength uint16
366 VendorID []byte
367 CPType uint8
368 CPLength uint16
369 CPValue []byte
370 NWType uint8
371 NWLength uint16
372 NWValue []byte
373 DVType uint8
374 DVLength uint16
375 DVValue []byte
376 SCPType uint8
377 SCPLength uint16
378 SCPValue []byte
379 PadType uint8
380 PadLength uint16
381 PadValue []byte
382 }
383 type args struct {
384 b gopacket.SerializeBuffer
385 opts gopacket.SerializeOptions
386 }
387 tests := []struct {
388 name string
389 fields fields
390 args args
391 wantErr bool
392 }{
393 // TODO: Add test cases.
394 {
395 name: "SerializeTo-1",
396 fields: fields{
397 // IEEE 1904.2
398 Opcode: 0xfd,
399 DiscoveryType: 0x01,
400 // Vendor-specific
401 VendorType: 0xfe,
402 Length: 37,
403 // Vendor ID
404 VendorIDType: 0xfd,
405 VendorIDLength: 3,
406 VendorID: []byte{0x2a, 0xea, 0x15},
407 // Controller Priority
408 CPType: 0x05,
409 CPLength: 1,
410 CPValue: []byte{128},
411 //NetworkID
412 NWType: 0x06,
413 NWLength: 16,
414 NWValue: []byte("tibitcom.com"),
415 //Device Type
416 DVType: 0x07,
417 DVLength: 1,
418 DVValue: []byte{1},
419 //Supported CLient Protocols
420 SCPType: 0x08,
421 SCPLength: 1,
422 SCPValue: []byte{0x03},
423 //Padding
424 PadType: 0xff,
425 PadLength: 1,
426 PadValue: []byte{0},
427 },
428 args: args{
429 b: gopacket.NewSerializeBufferExpectedSize(0, 36),
430 opts: gopacket.SerializeOptions{},
431 },
432 wantErr: false,
433 },
434 }
435 for _, tt := range tests {
436 t.Run(tt.name, func(t *testing.T) {
437 d := &DiscoverySolicit{
438 BaseLayer: tt.fields.BaseLayer,
439 Opcode: tt.fields.Opcode,
440 DiscoveryType: tt.fields.DiscoveryType,
441 VendorType: tt.fields.VendorType,
442 Length: tt.fields.Length,
443 VendorIDType: tt.fields.VendorIDType,
444 VendorIDLength: tt.fields.VendorIDLength,
445 VendorID: tt.fields.VendorID,
446 CPType: tt.fields.CPType,
447 CPLength: tt.fields.CPLength,
448 CPValue: tt.fields.CPValue,
449 NWType: tt.fields.NWType,
450 NWLength: tt.fields.NWLength,
451 NWValue: tt.fields.NWValue,
452 DVType: tt.fields.DVType,
453 DVLength: tt.fields.DVLength,
454 DVValue: tt.fields.DVValue,
455 SCPType: tt.fields.SCPType,
456 SCPLength: tt.fields.SCPLength,
457 SCPValue: tt.fields.SCPValue,
458 PadType: tt.fields.PadType,
459 PadLength: tt.fields.PadLength,
460 PadValue: tt.fields.PadValue,
461 }
462 if err := d.SerializeTo(tt.args.b, tt.args.opts); (err != nil) != tt.wantErr {
463 t.Errorf("DiscoverySolicit.SerializeTo error = %v, wantErr %v", err, tt.wantErr)
464 }
465
466 data := tt.args.b.Bytes()
467 cnt := 0
468 digits := 0
469 if !reflect.DeepEqual(d.Opcode, data[cnt]) {
470 t.Error("DiscoverySolicit.SerializeTo Opcode error")
471 }
472 cnt++
473 if !reflect.DeepEqual(d.DiscoveryType, data[cnt]) {
474 t.Error("DiscoverySolicit.SerializeTo DiscoveryType error")
475 }
476 cnt++
477 if !reflect.DeepEqual(d.VendorType, data[cnt]) {
478 t.Error("DiscoverySolicit.SerializeTo VendorType error")
479 }
480 cnt++
481
482 if !reflect.DeepEqual(d.Length, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
483 t.Error("DiscoverySolicit.SerializeTo Length error")
484 }
485 cnt += 2
486
487 if !reflect.DeepEqual(d.VendorIDType, data[cnt]) {
488 t.Error("DiscoverySolicit.SerializeTo VendorIDType error")
489 }
490 cnt++
491 if !reflect.DeepEqual(d.VendorIDLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
492 t.Error("DiscoverySolicit.SerializeTo VendorIDLength error")
493 }
494 cnt += 2
495 digits = int(d.VendorIDLength)
496 if !reflect.DeepEqual(d.VendorID, data[cnt:cnt+digits]) {
497 t.Error("DiscoverySolicit.SerializeTo VendorID error")
498 }
499 cnt += digits
500 if !reflect.DeepEqual(d.CPType, data[cnt]) {
501 t.Error("DiscoverySolicit.SerializeTo CPType error")
502 }
503 cnt++
504 if !reflect.DeepEqual(d.CPLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
505 t.Error("DiscoverySolicit.SerializeTo CPLength error")
506 }
507 cnt += 2
508 digits = int(d.CPLength)
509 if !reflect.DeepEqual(d.CPValue, data[cnt:cnt+digits]) {
510 t.Error("DiscoverySolicit.SerializeTo CPValue error")
511 }
512 cnt += digits
513 if !reflect.DeepEqual(d.NWType, data[cnt]) {
514 t.Error("DiscoverySolicit.SerializeTo NWType error")
515 }
516 cnt++
517 if !reflect.DeepEqual(d.NWLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
518 t.Error("DiscoverySolicit.SerializeTo NWLength error")
519 }
520 cnt += 2
521 //digits = int(d.NWLength)
522 for _, dvalue := range d.NWValue {
523 if !reflect.DeepEqual(dvalue, data[cnt]) {
524 t.Error("DiscoverySolicit.SerializeTo NWValue error")
525 }
526 cnt++
527 }
528 // if !reflect.DeepEqual(string(d.NWValue), string(data[cnt:cnt+digits])) {
529 // t.Errorf("DiscoverySolicit.SerializeTo NWValue error %x %x", d.NWValue, data[cnt:cnt+digits])
530 // }
531 cnt += 4
532 if !reflect.DeepEqual(d.DVType, data[cnt]) {
533 t.Error("DiscoverySolicit.SerializeTo DVType error")
534 }
535 cnt++
536 if !reflect.DeepEqual(d.DVLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
537 t.Error("DiscoverySolicit.SerializeTo DVLength error")
538 }
539 cnt += 2
540 digits = int(d.DVLength)
541 if !reflect.DeepEqual(d.DVValue, data[cnt:cnt+digits]) {
542 t.Error("DiscoverySolicit.SerializeTo DVValue error")
543 }
544 cnt += digits
545 if !reflect.DeepEqual(d.SCPType, data[cnt]) {
546 t.Error("DiscoverySolicit.SerializeTo SCPType error")
547 }
548 cnt++
549 if !reflect.DeepEqual(d.SCPLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
550 t.Error("DiscoverySolicit.SerializeTo SCPLength error")
551 }
552 cnt += 2
553 digits = int(d.SCPLength)
554 if !reflect.DeepEqual(d.SCPValue, data[cnt:cnt+digits]) {
555 t.Error("DiscoverySolicit.SerializeTo SCPValue error")
556 }
557 cnt += digits
558 if !reflect.DeepEqual(d.PadType, data[cnt]) {
559 t.Error("DiscoverySolicit.SerializeTo PadType error")
560 }
561 cnt++
562 if !reflect.DeepEqual(d.PadLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
563 t.Error("DiscoverySolicit.SerializeTo PadLength error")
564 }
565 cnt += 2
566 digits = int(d.PadLength)
567 if !reflect.DeepEqual(d.PadValue, data[cnt:cnt+digits]) {
568 t.Error("DiscoverySolicit.SerializeTo PadValue error")
569 }
570
571 })
572 }
573}
574
575func TestDiscoverySolicit_Decode(t *testing.T) {
576 type fields struct {
577 BaseLayer layers.BaseLayer
578 Opcode uint8
579 DiscoveryType uint8
580 VendorType uint8
581 Length uint16
582 VendorIDType uint8
583 VendorIDLength uint16
584 VendorID []byte
585 CPType uint8
586 CPLength uint16
587 CPValue []byte
588 NWType uint8
589 NWLength uint16
590 NWValue []byte
591 DVType uint8
592 DVLength uint16
593 DVValue []byte
594 SCPType uint8
595 SCPLength uint16
596 SCPValue []byte
597 PadType uint8
598 PadLength uint16
599 PadValue []byte
600 }
601 type args struct {
602 data []byte
603 }
604 tests := []struct {
605 name string
606 fields fields
607 args args
608 wantErr bool
609 }{
610 // TODO: Add test cases.
611 {
612 name: "Decode-1",
613 args: args{
614 data: []byte{0xfd, 0x01, 0xfe, 0x00, 0x25, 0xfd, 0x00, 0x03, 0x2a, 0xea, 0x15, 0x05, 0x00, 0x01, 0x80, 0x06, 0x00, 0x10, 0x74, 0x69, 0x62, 0x69, 0x74, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x01, 0x08, 0x00, 0x01, 0x03, 0xff, 0x00, 0x01, 0x00},
615 },
616 wantErr: false,
617 },
618 }
619 for _, tt := range tests {
620 t.Run(tt.name, func(t *testing.T) {
621 d := &DiscoverySolicit{
622 BaseLayer: tt.fields.BaseLayer,
623 Opcode: tt.fields.Opcode,
624 DiscoveryType: tt.fields.DiscoveryType,
625 VendorType: tt.fields.VendorType,
626 Length: tt.fields.Length,
627 VendorIDType: tt.fields.VendorIDType,
628 VendorIDLength: tt.fields.VendorIDLength,
629 VendorID: tt.fields.VendorID,
630 CPType: tt.fields.CPType,
631 CPLength: tt.fields.CPLength,
632 CPValue: tt.fields.CPValue,
633 NWType: tt.fields.NWType,
634 NWLength: tt.fields.NWLength,
635 NWValue: tt.fields.NWValue,
636 DVType: tt.fields.DVType,
637 DVLength: tt.fields.DVLength,
638 DVValue: tt.fields.DVValue,
639 SCPType: tt.fields.SCPType,
640 SCPLength: tt.fields.SCPLength,
641 SCPValue: tt.fields.SCPValue,
642 PadType: tt.fields.PadType,
643 PadLength: tt.fields.PadLength,
644 PadValue: tt.fields.PadValue,
645 }
646 if err := d.Decode(tt.args.data); (err != nil) != tt.wantErr {
647 t.Errorf("DiscoverySolicit.Decode error = %v, wantErr %v", err, tt.wantErr)
648 }
649
650 cnt := 0
651 digits := 0
652
653 if !reflect.DeepEqual(d.Opcode, tt.args.data[cnt]) {
654 t.Errorf("DiscoverySolicit.Decode Opcode error Opcode=%x,data=%x,cnt=%x", d.Opcode, tt.args.data[cnt:], cnt)
655 }
656 cnt++
657 if !reflect.DeepEqual(d.DiscoveryType, tt.args.data[cnt]) {
658 t.Errorf("DiscoverySolicit.Decode DiscoveryType error DiscoveryType=%X data=%x", d.DiscoveryType, tt.args.data[cnt:cnt+1])
659 }
660 cnt++
661 if !reflect.DeepEqual(d.VendorType, tt.args.data[cnt]) {
662 t.Errorf("DiscoverySolicit.Decode VendorType error %x %x", tt.args.data[cnt], d.VendorType)
663 }
664 cnt++
665
666 if !reflect.DeepEqual(d.Length, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
667 t.Errorf("DiscoverySolicit.Decode Length error Length=%x data[cnt:cnt+2]=%x", string(d.Length), string(binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])))
668 }
669 cnt += 2
670
671 if !reflect.DeepEqual(d.VendorIDType, tt.args.data[cnt]) {
672 t.Errorf("DiscoverySolicit.Decode VendorIDType error VendorIDType=%x data=%x", d.VendorIDType, tt.args.data[cnt])
673 }
674 cnt++
675 if !reflect.DeepEqual(d.VendorIDLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
676 t.Errorf("DiscoverySolicit.Decode VendorIDLength error VendorIDLength=%x data[cnt:cnt+2]=%x", d.VendorIDLength, tt.args.data[cnt:cnt+2])
677 }
678 cnt += 2
679 digits = int(d.VendorIDLength)
680 if !reflect.DeepEqual(d.VendorID, tt.args.data[cnt:cnt+digits]) {
681 t.Errorf("DiscoverySolicit.Decode VendorID error %v %v", d.VendorID, tt.args.data[cnt:cnt+3])
682 }
683 cnt += digits
684 if !reflect.DeepEqual(d.CPType, tt.args.data[cnt]) {
685 t.Error("DiscoverySolicit.Decode CPType error")
686 }
687 cnt++
688 if !reflect.DeepEqual(d.CPLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
689 t.Error("DiscoverySolicit.Decode CPLength error")
690 }
691 cnt += 2
692 digits = int(d.CPLength)
693 if !reflect.DeepEqual(d.CPValue, tt.args.data[cnt:cnt+digits]) {
694 t.Errorf("DiscoverySolicit.Decode CPValue error %x %x", tt.args.data[14:15], d.CPValue)
695 }
696 cnt += digits
697 if !reflect.DeepEqual(d.NWType, tt.args.data[cnt]) {
698 t.Error("DiscoverySolicit.Decode NWType error")
699 }
700 cnt++
701 if !reflect.DeepEqual(d.NWLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
702 t.Error("DiscoverySolicit.Decode NWLength error")
703 }
704 cnt += 2
705 //digits = int(d.NWLength)
706 for _, dvalue := range d.NWValue {
707 if !reflect.DeepEqual(dvalue, tt.args.data[cnt]) {
708 t.Errorf("DiscoverySolicit.Decode NWValue error %x %x", dvalue, tt.args.data[cnt])
709 }
710 cnt++
711 }
712 // if !reflect.DeepEqual(string(d.NWValue), string(tt.args.data[cnt:cnt+digits])) {
713 // t.Errorf("DiscoverySolicit.Decode NWValue error %x %x", d.NWValue, tt.args.data[cnt:cnt+digits])
714 // }
715 // cnt += 4
716 if !reflect.DeepEqual(d.DVType, tt.args.data[cnt]) {
717 t.Errorf("DiscoverySolicit.Decode DVType error %x %x", d.DVType, tt.args.data[cnt])
718 }
719 cnt++
720 if !reflect.DeepEqual(d.DVLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
721 t.Errorf("DiscoverySolicit.Decode DVLength error %x %x", d.DVLength, tt.args.data[cnt:cnt+2])
722 }
723 cnt += 2
724 digits = int(d.DVLength)
725 if !reflect.DeepEqual(d.DVValue, tt.args.data[cnt:cnt+digits]) {
726 t.Errorf("DiscoverySolicit.Decode DVValue error %x %x", d.DVValue, tt.args.data[cnt:cnt+digits])
727 }
728 cnt += digits
729 if !reflect.DeepEqual(d.SCPType, tt.args.data[cnt]) {
730 t.Errorf("DiscoverySolicit.Decode SCPType error %x %x", d.SCPType, tt.args.data[cnt])
731 }
732 cnt++
733 if !reflect.DeepEqual(d.SCPLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
734 t.Error("DiscoverySolicit.Decode SCPLength error")
735 }
736 cnt += 2
737 digits = int(d.SCPLength)
738 if !reflect.DeepEqual(d.SCPValue, tt.args.data[cnt:cnt+digits]) {
739 t.Errorf("DiscoverySolicit.Decode SCPValue error cnt= %x digits=%x", cnt, digits)
740 }
741 cnt += digits
742 if !reflect.DeepEqual(d.PadType, tt.args.data[cnt]) {
743 t.Error("DiscoverySolicit.Decode PadType error")
744 }
745 cnt++
746 if !reflect.DeepEqual(d.PadLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
747 t.Error("DiscoverySolicit.Decode PadLength error")
748 }
749 cnt += 2
750 digits = int(d.PadLength)
751 if !reflect.DeepEqual(d.PadValue, tt.args.data[cnt:cnt+digits]) {
752 t.Errorf("DiscoverySolicit.Decode PadValue error %x %x", d.PadValue, tt.args.data[cnt:cnt+digits])
753 }
754
755 })
756 }
757}
758
759func TestDiscoveryHello_String(t *testing.T) {
760 type fields struct {
761 BaseLayer layers.BaseLayer
762 Opcode uint8
763 DiscoveryType uint8
764 VendorType uint8
765 Length uint16
766 VendorIDType uint8
767 VendorIDLength uint16
768 VendorID []byte
769 NWType uint8
770 NWLength uint16
771 NWValue []byte
772 DVType uint8
773 DVLength uint16
774 DVValue []byte
775 SCPType uint8
776 SCPLength uint16
777 SCPValue []byte
778 TunnelType uint8
779 TunnelLength uint16
780 TunnelValue []byte
781 PadType uint8
782 PadLength uint16
783 PadValue []byte
784 }
785 tests := []struct {
786 name string
787 fields fields
788 want string
789 }{
790 // TODO: Add test cases.
791 {
792 name: "String-1",
793 fields: fields{
794 Opcode: 0xfd,
795 DiscoveryType: 0x01,
796 VendorType: 0xfe,
797 Length: 0x25,
798 VendorIDType: 0xfd,
799 VendorIDLength: 3,
800 VendorID: []byte{0x2a, 0xea, 0x15},
801 NWType: 0x06,
802 NWLength: 16,
803 NWValue: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16},
804 DVType: 0x07,
805 DVLength: 1,
806 DVValue: []byte{2},
807 SCPType: 0x08,
808 SCPLength: 1,
809 SCPValue: []byte{0x03},
810 TunnelType: 0x0a,
811 TunnelLength: 2,
812 TunnelValue: []byte{0x00, 0x01},
813 PadType: 0xff,
814 PadLength: 1,
815 PadValue: []byte{0},
816 },
817 want: "Opcode:253, DiscoveryType:1, VendorType:254, Length:37, VendorIDType:253, VendorIDLength:3, VendorID:2aea15, NWType:6, NWLength:16, NWValue:01020304050607080910111213141516, DVType:7, DVLength:1, DVValue:02, SCPType:8, SCPLength:1, SCPValue:03, TunnelType:10, TunnelLength:2, TunnelValue:0001, PadType:255, PadLength:1, PadValue:00",
818 },
819 }
820 for _, tt := range tests {
821 t.Run(tt.name, func(t *testing.T) {
822 d := &DiscoveryHello{
823 BaseLayer: tt.fields.BaseLayer,
824 Opcode: tt.fields.Opcode,
825 DiscoveryType: tt.fields.DiscoveryType,
826 VendorType: tt.fields.VendorType,
827 Length: tt.fields.Length,
828 VendorIDType: tt.fields.VendorIDType,
829 VendorIDLength: tt.fields.VendorIDLength,
830 VendorID: tt.fields.VendorID,
831 NWType: tt.fields.NWType,
832 NWLength: tt.fields.NWLength,
833 NWValue: tt.fields.NWValue,
834 DVType: tt.fields.DVType,
835 DVLength: tt.fields.DVLength,
836 DVValue: tt.fields.DVValue,
837 SCPType: tt.fields.SCPType,
838 SCPLength: tt.fields.SCPLength,
839 SCPValue: tt.fields.SCPValue,
840 TunnelType: tt.fields.TunnelType,
841 TunnelLength: tt.fields.TunnelLength,
842 TunnelValue: tt.fields.TunnelValue,
843 PadType: tt.fields.PadType,
844 PadLength: tt.fields.PadLength,
845 PadValue: tt.fields.PadValue,
846 }
847 if got := d.String(); got != tt.want {
848 t.Errorf("DiscoveryHello.String() = %v, want %v", got, tt.want)
849 }
850 })
851 }
852}
853
854func TestDiscoveryHello_Len(t *testing.T) {
855 type fields struct {
856 BaseLayer layers.BaseLayer
857 Opcode uint8
858 DiscoveryType uint8
859 VendorType uint8
860 Length uint16
861 VendorIDType uint8
862 VendorIDLength uint16
863 VendorID []byte
864 NWType uint8
865 NWLength uint16
866 NWValue []byte
867 DVType uint8
868 DVLength uint16
869 DVValue []byte
870 SCPType uint8
871 SCPLength uint16
872 SCPValue []byte
873 TunnelType uint8
874 TunnelLength uint16
875 TunnelValue []byte
876 PadType uint8
877 PadLength uint16
878 PadValue []byte
879 }
880 tests := []struct {
881 name string
882 fields fields
883 want int
884 }{
885 // TODO: Add test cases.
886 {
887 name: "Len-1",
888 fields: fields{
889 Opcode: 0xfd,
890 DiscoveryType: 0x01,
891 VendorType: 0xfe,
892 Length: 0x25,
893 VendorIDType: 0xfd,
894 VendorIDLength: 3,
895 VendorID: []byte{0x2a, 0xea, 0x15},
896 NWType: 0x06,
897 NWLength: 16,
898 NWValue: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16},
899 DVType: 0x07,
900 DVLength: 1,
901 DVValue: []byte{2},
902 SCPType: 0x08,
903 SCPLength: 1,
904 SCPValue: []byte{0x03},
905 TunnelType: 0x0a,
906 TunnelLength: 2,
907 TunnelValue: []byte{0x00, 0x01},
908 PadType: 0xff,
909 PadLength: 1,
910 PadValue: []byte{0},
911 },
912 want: 46,
913 },
914 }
915 for _, tt := range tests {
916 t.Run(tt.name, func(t *testing.T) {
917 d := &DiscoveryHello{
918 BaseLayer: tt.fields.BaseLayer,
919 Opcode: tt.fields.Opcode,
920 DiscoveryType: tt.fields.DiscoveryType,
921 VendorType: tt.fields.VendorType,
922 Length: tt.fields.Length,
923 VendorIDType: tt.fields.VendorIDType,
924 VendorIDLength: tt.fields.VendorIDLength,
925 VendorID: tt.fields.VendorID,
926 NWType: tt.fields.NWType,
927 NWLength: tt.fields.NWLength,
928 NWValue: tt.fields.NWValue,
929 DVType: tt.fields.DVType,
930 DVLength: tt.fields.DVLength,
931 DVValue: tt.fields.DVValue,
932 SCPType: tt.fields.SCPType,
933 SCPLength: tt.fields.SCPLength,
934 SCPValue: tt.fields.SCPValue,
935 TunnelType: tt.fields.TunnelType,
936 TunnelLength: tt.fields.TunnelLength,
937 TunnelValue: tt.fields.TunnelValue,
938 PadType: tt.fields.PadType,
939 PadLength: tt.fields.PadLength,
940 PadValue: tt.fields.PadValue,
941 }
942 if got := d.Len(); got != tt.want {
943 t.Errorf("DiscoveryHello.Len() = %v, want %v", got, tt.want)
944 }
945 })
946 }
947}
948
949func TestDiscoveryHello_LayerType(t *testing.T) {
950 type fields struct {
951 BaseLayer layers.BaseLayer
952 Opcode uint8
953 DiscoveryType uint8
954 VendorType uint8
955 Length uint16
956 VendorIDType uint8
957 VendorIDLength uint16
958 VendorID []byte
959 NWType uint8
960 NWLength uint16
961 NWValue []byte
962 DVType uint8
963 DVLength uint16
964 DVValue []byte
965 SCPType uint8
966 SCPLength uint16
967 SCPValue []byte
968 TunnelType uint8
969 TunnelLength uint16
970 TunnelValue []byte
971 PadType uint8
972 PadLength uint16
973 PadValue []byte
974 }
975 tests := []struct {
976 name string
977 fields fields
978 want gopacket.LayerType
979 }{
980 // TODO: Add test cases.
981 {
982 name: "LayerType-1",
983 want: layers.LayerTypeEthernet,
984 },
985 }
986 for _, tt := range tests {
987 t.Run(tt.name, func(t *testing.T) {
988 d := &DiscoveryHello{
989 BaseLayer: tt.fields.BaseLayer,
990 Opcode: tt.fields.Opcode,
991 DiscoveryType: tt.fields.DiscoveryType,
992 VendorType: tt.fields.VendorType,
993 Length: tt.fields.Length,
994 VendorIDType: tt.fields.VendorIDType,
995 VendorIDLength: tt.fields.VendorIDLength,
996 VendorID: tt.fields.VendorID,
997 NWType: tt.fields.NWType,
998 NWLength: tt.fields.NWLength,
999 NWValue: tt.fields.NWValue,
1000 DVType: tt.fields.DVType,
1001 DVLength: tt.fields.DVLength,
1002 DVValue: tt.fields.DVValue,
1003 SCPType: tt.fields.SCPType,
1004 SCPLength: tt.fields.SCPLength,
1005 SCPValue: tt.fields.SCPValue,
1006 TunnelType: tt.fields.TunnelType,
1007 TunnelLength: tt.fields.TunnelLength,
1008 TunnelValue: tt.fields.TunnelValue,
1009 PadType: tt.fields.PadType,
1010 PadLength: tt.fields.PadLength,
1011 PadValue: tt.fields.PadValue,
1012 }
1013 if got := d.LayerType(); !reflect.DeepEqual(got, tt.want) {
1014 t.Errorf("DiscoveryHello.LayerType() = %v, want %v", got, tt.want)
1015 }
1016 })
1017 }
1018}
1019
1020func TestDiscoveryHello_SerializeTo(t *testing.T) {
1021 type fields struct {
1022 BaseLayer layers.BaseLayer
1023 Opcode uint8
1024 DiscoveryType uint8
1025 VendorType uint8
1026 Length uint16
1027 VendorIDType uint8
1028 VendorIDLength uint16
1029 VendorID []byte
1030 NWType uint8
1031 NWLength uint16
1032 NWValue []byte
1033 DVType uint8
1034 DVLength uint16
1035 DVValue []byte
1036 SCPType uint8
1037 SCPLength uint16
1038 SCPValue []byte
1039 TunnelType uint8
1040 TunnelLength uint16
1041 TunnelValue []byte
1042 PadType uint8
1043 PadLength uint16
1044 PadValue []byte
1045 }
1046 type args struct {
1047 b gopacket.SerializeBuffer
1048 opts gopacket.SerializeOptions
1049 }
1050 tests := []struct {
1051 name string
1052 fields fields
1053 args args
1054 wantErr bool
1055 }{
1056 // TODO: Add test cases.
1057 {
1058 name: "SerializeTo-1",
1059 fields: fields{
1060 Opcode: 0xfd,
1061 DiscoveryType: 0x01,
1062 VendorType: 0xfe,
1063 Length: 0x25,
1064 VendorIDType: 0xfd,
1065 VendorIDLength: 3,
1066 VendorID: []byte{0x2a, 0xea, 0x15},
1067 NWType: 0x06,
1068 NWLength: 16,
1069 NWValue: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16},
1070 DVType: 0x07,
1071 DVLength: 1,
1072 DVValue: []byte{2},
1073 SCPType: 0x08,
1074 SCPLength: 1,
1075 SCPValue: []byte{0x03},
1076 TunnelType: 0x0a,
1077 TunnelLength: 2,
1078 TunnelValue: []byte{0x00, 0x01},
1079 PadType: 0xff,
1080 PadLength: 1,
1081 PadValue: []byte{0},
1082 },
1083 args: args{
1084 b: gopacket.NewSerializeBufferExpectedSize(0, 46),
1085 opts: gopacket.SerializeOptions{},
1086 },
1087 wantErr: false,
1088 },
1089 }
1090 for _, tt := range tests {
1091 t.Run(tt.name, func(t *testing.T) {
1092 d := &DiscoveryHello{
1093 BaseLayer: tt.fields.BaseLayer,
1094 Opcode: tt.fields.Opcode,
1095 DiscoveryType: tt.fields.DiscoveryType,
1096 VendorType: tt.fields.VendorType,
1097 Length: tt.fields.Length,
1098 VendorIDType: tt.fields.VendorIDType,
1099 VendorIDLength: tt.fields.VendorIDLength,
1100 VendorID: tt.fields.VendorID,
1101 NWType: tt.fields.NWType,
1102 NWLength: tt.fields.NWLength,
1103 NWValue: tt.fields.NWValue,
1104 DVType: tt.fields.DVType,
1105 DVLength: tt.fields.DVLength,
1106 DVValue: tt.fields.DVValue,
1107 SCPType: tt.fields.SCPType,
1108 SCPLength: tt.fields.SCPLength,
1109 SCPValue: tt.fields.SCPValue,
1110 TunnelType: tt.fields.TunnelType,
1111 TunnelLength: tt.fields.TunnelLength,
1112 TunnelValue: tt.fields.TunnelValue,
1113 PadType: tt.fields.PadType,
1114 PadLength: tt.fields.PadLength,
1115 PadValue: tt.fields.PadValue,
1116 }
1117 if err := d.SerializeTo(tt.args.b, tt.args.opts); (err != nil) != tt.wantErr {
1118 t.Errorf("DiscoveryHello.SerializeTo() error = %v, wantErr %v", err, tt.wantErr)
1119 }
1120
1121 data := tt.args.b.Bytes()
1122 cnt := 0
1123 digits := 0
1124 if !reflect.DeepEqual(d.Opcode, data[cnt]) {
1125 t.Errorf("DiscoverySolicit.SerializeTo Opcode error Opcode=%x,data=%x,cnt=%x", d.Opcode, data[cnt:], cnt)
1126 }
1127 cnt++
1128 if !reflect.DeepEqual(d.DiscoveryType, data[cnt]) {
1129 t.Errorf("DiscoverySolicit.SerializeTo DiscoveryType error DiscoveryType=%X data=%x", d.DiscoveryType, data[cnt:cnt+1])
1130 }
1131 cnt++
1132 if !reflect.DeepEqual(d.VendorType, data[cnt]) {
1133 t.Errorf("DiscoverySolicit.SerializeTo VendorType error %x %x", data[cnt], d.VendorType)
1134 }
1135 cnt++
1136
1137 if !reflect.DeepEqual(d.Length, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
1138 t.Errorf("DiscoverySolicit.SerializeTo Length error Length=%x data[cnt:cnt+2]=%x", string(d.Length), string(binary.BigEndian.Uint16(data[cnt:cnt+2])))
1139 }
1140 cnt += 2
1141
1142 if !reflect.DeepEqual(d.VendorIDType, data[cnt]) {
1143 t.Errorf("DiscoverySolicit.SerializeTo VendorIDType error VendorIDType=%x data=%x", d.VendorIDType, data[cnt])
1144 }
1145 cnt++
1146 if !reflect.DeepEqual(d.VendorIDLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
1147 t.Errorf("DiscoverySolicit.SerializeTo VendorIDLength error VendorIDLength=%x data[cnt:cnt+2]=%x", d.VendorIDLength, data[cnt:cnt+2])
1148 }
1149 cnt += 2
1150 digits = int(d.VendorIDLength)
1151 if !reflect.DeepEqual(d.VendorID, data[cnt:cnt+digits]) {
1152 t.Errorf("DiscoverySolicit.SerializeTo VendorID error %v %v", d.VendorID, data[cnt:cnt+3])
1153 }
1154 cnt += digits
1155 if !reflect.DeepEqual(d.NWType, data[cnt]) {
1156 t.Error("DiscoverySolicit.SerializeTo NWType error")
1157 }
1158 cnt++
1159 if !reflect.DeepEqual(d.NWLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
1160 t.Error("DiscoverySolicit.SerializeTo NWLength error")
1161 }
1162 cnt += 2
1163 //digits = int(d.NWLength)
1164 for _, dvalue := range d.NWValue {
1165 if !reflect.DeepEqual(dvalue, data[cnt]) {
1166 t.Errorf("DiscoverySolicit.SerializeTo NWValue error %x %x", dvalue, data[cnt])
1167 }
1168 cnt++
1169 }
1170 // if !reflect.DeepEqual(string(d.NWValue), string(data[cnt:cnt+digits])) {
1171 // t.Errorf("DiscoverySolicit.SerializeTo NWValue error %x %x", d.NWValue, data[cnt:cnt+digits])
1172 // }
1173 // cnt += 16
1174 if !reflect.DeepEqual(d.DVType, data[cnt]) {
1175 t.Error("DiscoverySolicit.SerializeTo DVType error")
1176 }
1177 cnt++
1178 if !reflect.DeepEqual(d.DVLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
1179 t.Error("DiscoverySolicit.SerializeTo DVLength error")
1180 }
1181 cnt += 2
1182 digits = int(d.DVLength)
1183 if !reflect.DeepEqual(d.DVValue, data[cnt:cnt+digits]) {
1184 t.Error("DiscoverySolicit.SerializeTo DVValue error")
1185 }
1186 cnt += digits
1187 if !reflect.DeepEqual(d.SCPType, data[cnt]) {
1188 t.Error("DiscoverySolicit.SerializeTo SCPType error")
1189 }
1190 cnt++
1191 if !reflect.DeepEqual(d.SCPLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
1192 t.Error("DiscoverySolicit.SerializeTo SCPLength error")
1193 }
1194 cnt += 2
1195 digits = int(d.SCPLength)
1196 if !reflect.DeepEqual(d.SCPValue, data[cnt:cnt+digits]) {
1197 t.Error("DiscoverySolicit.SerializeTo SCPValue error")
1198 }
1199 cnt += digits
1200 if !reflect.DeepEqual(d.TunnelType, data[cnt]) {
1201 t.Error("DiscoverySolicit.SerializeTo TunnelType error")
1202 }
1203 cnt++
1204 if !reflect.DeepEqual(d.TunnelLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
1205 t.Error("DiscoverySolicit.SerializeTo TunnelLength error")
1206 }
1207 cnt += 2
1208 digits = int(d.TunnelLength)
1209 if !reflect.DeepEqual(d.TunnelValue, data[cnt:cnt+digits]) {
1210 t.Error("DiscoverySolicit.SerializeTo TunnelValue error")
1211 }
1212 cnt += digits
1213 if !reflect.DeepEqual(d.PadType, data[cnt]) {
1214 t.Error("DiscoverySolicit.SerializeTo PadType error")
1215 }
1216 cnt++
1217 if !reflect.DeepEqual(d.PadLength, binary.BigEndian.Uint16(data[cnt:cnt+2])) {
1218 t.Error("DiscoverySolicit.SerializeTo PadLength error")
1219 }
1220 cnt += 2
1221 digits = int(d.PadLength)
1222 if !reflect.DeepEqual(d.PadValue, data[cnt:cnt+digits]) {
1223 t.Errorf("DiscoverySolicit.SerializeTo PadValue error %x %x", d.PadValue, data[cnt:cnt+digits])
1224 }
1225 })
1226 }
1227}
1228
1229func TestDiscoveryHello_Decode(t *testing.T) {
1230 type fields struct {
1231 BaseLayer layers.BaseLayer
1232 Opcode uint8
1233 DiscoveryType uint8
1234 VendorType uint8
1235 Length uint16
1236 VendorIDType uint8
1237 VendorIDLength uint16
1238 VendorID []byte
1239 NWType uint8
1240 NWLength uint16
1241 NWValue []byte
1242 DVType uint8
1243 DVLength uint16
1244 DVValue []byte
1245 SCPType uint8
1246 SCPLength uint16
1247 SCPValue []byte
1248 TunnelType uint8
1249 TunnelLength uint16
1250 TunnelValue []byte
1251 PadType uint8
1252 PadLength uint16
1253 PadValue []byte
1254 }
1255 type args struct {
1256 data []byte
1257 }
1258 tests := []struct {
1259 name string
1260 fields fields
1261 args args
1262 wantErr bool
1263 }{
1264 // TODO: Add test cases.
1265 {
1266 name: "Decode-1",
1267 args: args{
1268 data: []byte{0xfd, 0x02, 0xfe, 0x00, 0x26, 0xfd, 0x00, 0x03, 0x2a, 0xea, 0x15, 0x06, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x07, 0x00, 0x01, 0x02, 0x08, 0x00, 0x01, 0x03, 0x0a, 0x00, 0x02, 0x00, 0x01, 0xff, 0x00, 0x01, 0x00},
1269 },
1270 wantErr: false,
1271 },
1272 }
1273 for _, tt := range tests {
1274 t.Run(tt.name, func(t *testing.T) {
1275 d := &DiscoveryHello{
1276 BaseLayer: tt.fields.BaseLayer,
1277 Opcode: tt.fields.Opcode,
1278 DiscoveryType: tt.fields.DiscoveryType,
1279 VendorType: tt.fields.VendorType,
1280 Length: tt.fields.Length,
1281 VendorIDType: tt.fields.VendorIDType,
1282 VendorIDLength: tt.fields.VendorIDLength,
1283 VendorID: tt.fields.VendorID,
1284 NWType: tt.fields.NWType,
1285 NWLength: tt.fields.NWLength,
1286 NWValue: tt.fields.NWValue,
1287 DVType: tt.fields.DVType,
1288 DVLength: tt.fields.DVLength,
1289 DVValue: tt.fields.DVValue,
1290 SCPType: tt.fields.SCPType,
1291 SCPLength: tt.fields.SCPLength,
1292 SCPValue: tt.fields.SCPValue,
1293 TunnelType: tt.fields.TunnelType,
1294 TunnelLength: tt.fields.TunnelLength,
1295 TunnelValue: tt.fields.TunnelValue,
1296 PadType: tt.fields.PadType,
1297 PadLength: tt.fields.PadLength,
1298 PadValue: tt.fields.PadValue,
1299 }
1300 if err := d.Decode(tt.args.data); (err != nil) != tt.wantErr {
1301 t.Errorf("DiscoveryHello.Decode() error = %v, wantErr %v", err, tt.wantErr)
1302 }
1303
1304 cnt := 0
1305 digits := 0
1306 if !reflect.DeepEqual(d.Opcode, tt.args.data[cnt]) {
1307 t.Errorf("DiscoverySolicit.Decode Opcode error Opcode=%x,data=%x,cnt=%x", d.Opcode, tt.args.data[cnt:], cnt)
1308 }
1309 cnt++
1310 if !reflect.DeepEqual(d.DiscoveryType, tt.args.data[cnt]) {
1311 t.Errorf("DiscoverySolicit.Decode DiscoveryType error DiscoveryType=%X data=%x", d.DiscoveryType, tt.args.data[cnt:cnt+1])
1312 }
1313 cnt++
1314 if !reflect.DeepEqual(d.VendorType, tt.args.data[cnt]) {
1315 t.Errorf("DiscoverySolicit.Decode VendorType error %x %x", tt.args.data[cnt], d.VendorType)
1316 }
1317 cnt++
1318
1319 if !reflect.DeepEqual(d.Length, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
1320 t.Errorf("DiscoverySolicit.Decode Length error Length=%x data[cnt:cnt+2]=%x", string(d.Length), string(binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])))
1321 }
1322 cnt += 2
1323
1324 if !reflect.DeepEqual(d.VendorIDType, tt.args.data[cnt]) {
1325 t.Errorf("DiscoverySolicit.Decode VendorIDType error VendorIDType=%x data=%x", d.VendorIDType, tt.args.data[cnt])
1326 }
1327 cnt++
1328 if !reflect.DeepEqual(d.VendorIDLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
1329 t.Errorf("DiscoverySolicit.Decode VendorIDLength error VendorIDLength=%x data[cnt:cnt+2]=%x", d.VendorIDLength, tt.args.data[cnt:cnt+2])
1330 }
1331 cnt += 2
1332 digits = int(d.VendorIDLength)
1333 if !reflect.DeepEqual(d.VendorID, tt.args.data[cnt:cnt+digits]) {
1334 t.Errorf("DiscoverySolicit.Decode VendorID error %v %v", d.VendorID, tt.args.data[cnt:cnt+3])
1335 }
1336 cnt += digits
1337 if !reflect.DeepEqual(d.NWType, tt.args.data[cnt]) {
1338 t.Error("DiscoverySolicit.Decode NWType error")
1339 }
1340 cnt++
1341 if !reflect.DeepEqual(d.NWLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
1342 t.Error("DiscoverySolicit.Decode NWLength error")
1343 }
1344 cnt += 2
1345 //digits = int(d.NWLength)
1346 for _, dvalue := range d.NWValue {
1347 if !reflect.DeepEqual(dvalue, tt.args.data[cnt]) {
1348 t.Errorf("DiscoverySolicit.Decode NWValue error %x %x", dvalue, tt.args.data[cnt])
1349 }
1350 cnt++
1351 }
1352 // if !reflect.DeepEqual(string(d.NWValue), string(tt.args.data[cnt:cnt+digits])) {
1353 // t.Errorf("DiscoverySolicit.Decode NWValue error %x %x", d.NWValue, tt.args.data[cnt:cnt+digits])
1354 // }
1355 // cnt += 16
1356 if !reflect.DeepEqual(d.DVType, tt.args.data[cnt]) {
1357 t.Error("DiscoverySolicit.Decode DVType error")
1358 }
1359 cnt++
1360 if !reflect.DeepEqual(d.DVLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
1361 t.Error("DiscoverySolicit.Decode DVLength error")
1362 }
1363 cnt += 2
1364 digits = int(d.DVLength)
1365 if !reflect.DeepEqual(d.DVValue, tt.args.data[cnt:cnt+digits]) {
1366 t.Error("DiscoverySolicit.Decode DVValue error")
1367 }
1368 cnt += digits
1369 if !reflect.DeepEqual(d.SCPType, tt.args.data[cnt]) {
1370 t.Error("DiscoverySolicit.Decode SCPType error")
1371 }
1372 cnt++
1373 if !reflect.DeepEqual(d.SCPLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
1374 t.Error("DiscoverySolicit.Decode SCPLength error")
1375 }
1376 cnt += 2
1377 digits = int(d.SCPLength)
1378 if !reflect.DeepEqual(d.SCPValue, tt.args.data[cnt:cnt+digits]) {
1379 t.Error("DiscoverySolicit.Decode SCPValue error")
1380 }
1381 cnt += digits
1382 if !reflect.DeepEqual(d.TunnelType, tt.args.data[cnt]) {
1383 t.Error("DiscoverySolicit.Decode TunnelType error")
1384 }
1385 cnt++
1386 if !reflect.DeepEqual(d.TunnelLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
1387 t.Error("DiscoverySolicit.Decode TunnelLength error")
1388 }
1389 cnt += 2
1390 digits = int(d.TunnelLength)
1391 if !reflect.DeepEqual(d.TunnelValue, tt.args.data[cnt:cnt+digits]) {
1392 t.Error("DiscoverySolicit.Decode TunnelValue error")
1393 }
1394 cnt += digits
1395 if !reflect.DeepEqual(d.PadType, tt.args.data[cnt]) {
1396 t.Error("DiscoverySolicit.Decode PadType error")
1397 }
1398 cnt++
1399 if !reflect.DeepEqual(d.PadLength, binary.BigEndian.Uint16(tt.args.data[cnt:cnt+2])) {
1400 t.Error("DiscoverySolicit.Decode PadLength error")
1401 }
1402 cnt += 2
1403 digits = int(d.PadLength)
1404 if !reflect.DeepEqual(d.PadValue, tt.args.data[cnt:cnt+digits]) {
1405 t.Errorf("DiscoverySolicit.Decode PadValue error %x %x", d.PadValue, tt.args.data[cnt:cnt+digits])
1406 }
1407 })
1408 }
1409}