summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/github.com/google/gopacket/layers/ospf_test.go
blob: 766f62ef2018ffb0545d492fc0a1256505788f2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
// Copyright 2017 Google, Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.

package layers

import (
	"reflect"
	"testing"

	"github.com/google/gopacket"
)

// testPacketOSPF2Hello is the packet:
// 13:19:20.008765 IP 192.168.170.8 > 224.0.0.5: OSPFv2, Hello, length 44
//	0x0000:  0100 5e00 0005 00e0 18b1 0cad 0800 45c0  ..^...........E.
//	0x0010:  0040 0812 0000 0159 65dd c0a8 aa08 e000  .@.....Ye.......
//	0x0020:  0005 0201 002c c0a8 aa08 0000 0001 273b  .....,........';
//	0x0030:  0000 0000 0000 0000 0000 ffff ff00 000a  ................
//	0x0040:  0201 0000 0028 c0a8 aa08 0000 0000       .....(........
var testPacketOSPF2Hello = []byte{
	0x01, 0x00, 0x5e, 0x00, 0x00, 0x05, 0x00, 0xe0, 0x18, 0xb1, 0x0c, 0xad, 0x08, 0x00, 0x45, 0xc0,
	0x00, 0x40, 0x08, 0x12, 0x00, 0x00, 0x01, 0x59, 0x65, 0xdd, 0xc0, 0xa8, 0xaa, 0x08, 0xe0, 0x00,
	0x00, 0x05, 0x02, 0x01, 0x00, 0x2c, 0xc0, 0xa8, 0xaa, 0x08, 0x00, 0x00, 0x00, 0x01, 0x27, 0x3b,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x0a,
	0x02, 0x01, 0x00, 0x00, 0x00, 0x28, 0xc0, 0xa8, 0xaa, 0x08, 0x00, 0x00, 0x00, 0x00,
}

func TestPacketOSPF2Hello(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF2Hello, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeOSPF}, t)

	ospf := p.Layer(LayerTypeOSPF).(*OSPFv2)
	if ospf.Version != 2 {
		t.Fatal("Invalid OSPF version")
	}
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv2); ok {
		want := &OSPFv2{
			OSPF: OSPF{
				Version:      2,
				Type:         OSPFHello,
				PacketLength: 44,
				RouterID:     0xc0a8aa08,
				AreaID:       1,
				Checksum:     0x273b,
				Content: HelloPkgV2{
					NetworkMask: 0xffffff00,
					HelloPkg: HelloPkg{
						RtrPriority:              0x1,
						Options:                  0x2,
						HelloInterval:            0xa,
						RouterDeadInterval:       0x28,
						DesignatedRouterID:       0xc0a8aa08,
						BackupDesignatedRouterID: 0x0,
					},
				},
			},
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket5(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF2Hello, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF3Hello is the packet:
//   14:43:11.663317 IP6 fe80::1 > ff02::5: OSPFv3, Hello, length 36
//   	0x0000:  3333 0000 0005 c200 1ffa 0001 86dd 6e00  33............n.
//   	0x0010:  0000 0024 5901 fe80 0000 0000 0000 0000  ...$Y...........
//   	0x0020:  0000 0000 0001 ff02 0000 0000 0000 0000  ................
//   	0x0030:  0000 0000 0005 0301 0024 0101 0101 0000  .........$......
//   	0x0040:  0001 fb86 0000 0000 0005 0100 0013 000a  ................
//   	0x0050:  0028 0000 0000 0000 0000                 .(........
var testPacketOSPF3Hello = []byte{
	0x33, 0x33, 0x00, 0x00, 0x00, 0x05, 0xc2, 0x00, 0x1f, 0xfa, 0x00, 0x01, 0x86, 0xdd, 0x6e, 0x00,
	0x00, 0x00, 0x00, 0x24, 0x59, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x01, 0x00, 0x24, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
	0x00, 0x01, 0xfb, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x13, 0x00, 0x0a,
	0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}

func TestPacketOSPF3Hello(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF3Hello, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeOSPF}, t)

	ospf := p.Layer(LayerTypeOSPF).(*OSPFv3)
	if ospf.Version != 3 {
		t.Fatal("Invalid OSPF version")
	}
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv3); ok {
		want := &OSPFv3{
			OSPF: OSPF{
				Version:      3,
				Type:         OSPFHello,
				PacketLength: 36,
				RouterID:     0x1010101,
				AreaID:       1,
				Checksum:     0xfb86,
				Content: HelloPkg{
					InterfaceID:              5,
					RtrPriority:              1,
					Options:                  0x000013,
					HelloInterval:            10,
					RouterDeadInterval:       40,
					DesignatedRouterID:       0,
					BackupDesignatedRouterID: 0,
				},
			},
			Instance: 0,
			Reserved: 0,
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket0(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF3Hello, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF2DBDesc is the packet:
// 13:20:14.414477 IP 192.168.170.8 > 192.168.170.2: OSPFv2, Database Description, length 32
//	0x0000:  0060 0881 7a70 00e0 18b1 0cad 0800 45c0  .`..zp........E.
//	0x0010:  0034 2be5 0000 0159 b770 c0a8 aa08 c0a8  .4+....Y.p......
//	0x0020:  aa02 0202 0020 c0a8 aa08 0000 0001 a052  ...............R
//	0x0030:  0000 0000 0000 0000 0000 05dc 0207 4177  ..............Aw
//	0x0040:  a97e                                     .~
var testPacketOSPF2DBDesc = []byte{
	0x00, 0x60, 0x08, 0x81, 0x7a, 0x70, 0x00, 0xe0, 0x18, 0xb1, 0x0c, 0xad, 0x08, 0x00, 0x45, 0xc0,
	0x00, 0x34, 0x2b, 0xe5, 0x00, 0x00, 0x01, 0x59, 0xb7, 0x70, 0xc0, 0xa8, 0xaa, 0x08, 0xc0, 0xa8,
	0xaa, 0x02, 0x02, 0x02, 0x00, 0x20, 0xc0, 0xa8, 0xaa, 0x08, 0x00, 0x00, 0x00, 0x01, 0xa0, 0x52,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xdc, 0x02, 0x07, 0x41, 0x77,
	0xa9, 0x7e,
}

func TestPacketOSPF2DBDesc(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF2DBDesc, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeOSPF}, t)
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv2); ok {
		want := &OSPFv2{
			OSPF: OSPF{
				Version:      2,
				Type:         OSPFDatabaseDescription,
				PacketLength: 32,
				RouterID:     0xc0a8aa08,
				AreaID:       1,
				Checksum:     0xa052,
				Content: DbDescPkg{
					Options:      0x02,
					InterfaceMTU: 1500,
					Flags:        0x7,
					DDSeqNumber:  1098361214,
				},
			},
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket6(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF2DBDesc, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF3DBDesc is the packet:
//   14:43:51.657571 IP6 fe80::2 > fe80::1: OSPFv3, Database Description, length 28
//   	0x0000:  c200 1ffa 0001 c201 1ffa 0001 86dd 6e00  ..............n.
//   	0x0010:  0000 001c 5901 fe80 0000 0000 0000 0000  ....Y...........
//   	0x0020:  0000 0000 0002 fe80 0000 0000 0000 0000  ................
//   	0x0030:  0000 0000 0001 0302 001c 0202 0202 0000  ................
//   	0x0040:  0001 d826 0000 0000 0013 05dc 0007 0000  ...&............
//   	0x0050:  1d46                                     .F
var testPacketOSPF3DBDesc = []byte{
	0xc2, 0x00, 0x1f, 0xfa, 0x00, 0x01, 0xc2, 0x01, 0x1f, 0xfa, 0x00, 0x01, 0x86, 0xdd, 0x6e, 0x00,
	0x00, 0x00, 0x00, 0x1c, 0x59, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x02, 0x00, 0x1c, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00,
	0x00, 0x01, 0xd8, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x05, 0xdc, 0x00, 0x07, 0x00, 0x00,
	0x1d, 0x46,
}

func TestPacketOSPF3DBDesc(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF3DBDesc, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeOSPF}, t)
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv3); ok {
		want := &OSPFv3{
			OSPF: OSPF{
				Version:      3,
				Type:         OSPFDatabaseDescription,
				PacketLength: 28,
				RouterID:     0x2020202,
				AreaID:       1,
				Checksum:     0xd826,
				Content: DbDescPkg{
					Options:      0x000013,
					InterfaceMTU: 1500,
					Flags:        0x7,
					DDSeqNumber:  7494,
				},
			},
			Instance: 0,
			Reserved: 0,
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket1(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF3DBDesc, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF2LSRequest is the packet:
// 13:20:14.418003 IP 192.168.170.2 > 192.168.170.8: OSPFv2, LS-Request, length 36
//	0x0000:  00e0 18b1 0cad 0060 0881 7a70 0800 45c0  .......`..zp..E.
//	0x0010:  0038 88c6 0000 0159 5a8b c0a8 aa02 c0a8  .8.....YZ.......
//	0x0020:  aa08 0203 0024 c0a8 aa03 0000 0001 bdc7  .....$..........
//	0x0030:  0000 0000 0000 0000 0000 0000 0001 c0a8  ................
//	0x0040:  aa08 c0a8 aa08                           ......
var testPacketOSPF2LSRequest = []byte{
	0x00, 0xe0, 0x18, 0xb1, 0x0c, 0xad, 0x00, 0x60, 0x08, 0x81, 0x7a, 0x70, 0x08, 0x00, 0x45, 0xc0,
	0x00, 0x38, 0x88, 0xc6, 0x00, 0x00, 0x01, 0x59, 0x5a, 0x8b, 0xc0, 0xa8, 0xaa, 0x02, 0xc0, 0xa8,
	0xaa, 0x08, 0x02, 0x03, 0x00, 0x24, 0xc0, 0xa8, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x01, 0xbd, 0xc7,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0xa8,
	0xaa, 0x08, 0xc0, 0xa8, 0xaa, 0x08,
}

func TestPacketOSPF2LSRequest(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF2LSRequest, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeOSPF}, t)
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv2); ok {
		want := &OSPFv2{
			OSPF: OSPF{
				Version:      2,
				Type:         OSPFLinkStateRequest,
				PacketLength: 36,
				RouterID:     0xc0a8aa03,
				AreaID:       1,
				Checksum:     0xbdc7,
				Content: []LSReq{
					LSReq{
						LSType:    0x1,
						LSID:      0xc0a8aa08,
						AdvRouter: 0xc0a8aa08,
					},
				},
			},
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket7(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF2LSRequest, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF3LSRequest is the packet:
//   14:43:51.673584 IP6 fe80::2 > fe80::1: OSPFv3, LS-Request, length 100
//   	0x0000:  c200 1ffa 0001 c201 1ffa 0001 86dd 6e00  ..............n.
//   	0x0010:  0000 0064 5901 fe80 0000 0000 0000 0000  ...dY...........
//   	0x0020:  0000 0000 0002 fe80 0000 0000 0000 0000  ................
//   	0x0030:  0000 0000 0001 0303 0064 0202 0202 0000  .........d......
//   	0x0040:  0001 2c9a 0000 0000 2001 0000 0000 0101  ..,.............
//   	0x0050:  0101 0000 2003 0000 0003 0101 0101 0000  ................
//   	0x0060:  2003 0000 0002 0101 0101 0000 2003 0000  ................
//   	0x0070:  0001 0101 0101 0000 2003 0000 0000 0101  ................
//   	0x0080:  0101 0000 0008 0000 0005 0101 0101 0000  ................
//   	0x0090:  2009 0000 0000 0101 0101                 ..........
var testPacketOSPF3LSRequest = []byte{
	0xc2, 0x00, 0x1f, 0xfa, 0x00, 0x01, 0xc2, 0x01, 0x1f, 0xfa, 0x00, 0x01, 0x86, 0xdd, 0x6e, 0x00,
	0x00, 0x00, 0x00, 0x64, 0x59, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x00, 0x64, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00,
	0x00, 0x01, 0x2c, 0x9a, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
	0x01, 0x01, 0x00, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
	0x20, 0x03, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x20, 0x03, 0x00, 0x00,
	0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
	0x01, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x05, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
	0x20, 0x09, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
}

func TestPacketOSPF3LSRequest(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF3LSRequest, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeOSPF}, t)
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv3); ok {
		want := &OSPFv3{
			OSPF: OSPF{
				Version:      3,
				Type:         OSPFLinkStateRequest,
				PacketLength: 100,
				RouterID:     0x2020202,
				AreaID:       1,
				Checksum:     0x2c9a,
				Content: []LSReq{
					LSReq{
						LSType:    0x2001,
						LSID:      0x00000000,
						AdvRouter: 0x01010101,
					},
					LSReq{
						LSType:    0x2003,
						LSID:      0x00000003,
						AdvRouter: 0x01010101,
					},
					LSReq{
						LSType:    0x2003,
						LSID:      0x00000002,
						AdvRouter: 0x01010101,
					},
					LSReq{
						LSType:    0x2003,
						LSID:      0x00000001,
						AdvRouter: 0x01010101,
					},
					LSReq{
						LSType:    0x2003,
						LSID:      0x00000000,
						AdvRouter: 0x01010101,
					},
					LSReq{
						LSType:    0x0008,
						LSID:      0x00000005,
						AdvRouter: 0x01010101,
					},
					LSReq{
						LSType:    0x2009,
						LSID:      0x00000000,
						AdvRouter: 0x01010101,
					},
				},
			},
			Instance: 0,
			Reserved: 0,
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket2(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF3LSRequest, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF2LSUpdate is the packet:
// 13:20:14.420459 IP 192.168.170.2 > 224.0.0.6: OSPFv2, LS-Update, length 292
//	0x0000:  0100 5e00 0006 0060 0881 7a70 0800 45c0  ..^....`..zp..E.
//	0x0010:  0138 3025 0000 0159 3cd7 c0a8 aa02 e000  .80%...Y<.......
//	0x0020:  0006 0204 0124 c0a8 aa03 0000 0001 366b  .....$........6k
//	0x0030:  0000 0000 0000 0000 0000 0000 0007 0002  ................
//	0x0040:  0201 c0a8 aa03 c0a8 aa03 8000 0001 3a9c  ..............:.
//	0x0050:  0030 0200 0002 c0a8 aa00 ffff ff00 0300  .0..............
//	0x0060:  000a c0a8 aa00 ffff ff00 0300 000a 0003  ................
//	0x0070:  0205 50d4 1000 c0a8 aa02 8000 0001 2a49  ..P...........*I
//	0x0080:  0024 ffff ffff 8000 0014 0000 0000 0000  .$..............
//	0x0090:  0000 0003 0205 9479 ab00 c0a8 aa02 8000  .......y........
//	0x00a0:  0001 34a5 0024 ffff ff00 8000 0014 c0a8  ..4..$..........
//	0x00b0:  aa01 0000 0000 0003 0205 c082 7800 c0a8  ............x...
//	0x00c0:  aa02 8000 0001 d319 0024 ffff ff00 8000  .........$......
//	0x00d0:  0014 0000 0000 0000 0000 0003 0205 c0a8  ................
//	0x00e0:  0000 c0a8 aa02 8000 0001 3708 0024 ffff  ..........7..$..
//	0x00f0:  ff00 8000 0014 0000 0000 0000 0000 0003  ................
//	0x0100:  0205 c0a8 0100 c0a8 aa02 8000 0001 2c12  ..............,.
//	0x0110:  0024 ffff ff00 8000 0014 0000 0000 0000  .$..............
//	0x0120:  0000 0003 0205 c0a8 ac00 c0a8 aa02 8000  ................
//	0x0130:  0001 3341 0024 ffff ff00 8000 0014 c0a8  ..3A.$..........
//	0x0140:  aa0a 0000 0000                           ......
var testPacketOSPF2LSUpdate = []byte{
	0x01, 0x00, 0x5e, 0x00, 0x00, 0x06, 0x00, 0x60, 0x08, 0x81, 0x7a, 0x70, 0x08, 0x00, 0x45, 0xc0,
	0x01, 0x38, 0x30, 0x25, 0x00, 0x00, 0x01, 0x59, 0x3c, 0xd7, 0xc0, 0xa8, 0xaa, 0x02, 0xe0, 0x00,
	0x00, 0x06, 0x02, 0x04, 0x01, 0x24, 0xc0, 0xa8, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x01, 0x36, 0x6b,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x02,
	0x02, 0x01, 0xc0, 0xa8, 0xaa, 0x03, 0xc0, 0xa8, 0xaa, 0x03, 0x80, 0x00, 0x00, 0x01, 0x3a, 0x9c,
	0x00, 0x30, 0x02, 0x00, 0x00, 0x02, 0xc0, 0xa8, 0xaa, 0x00, 0xff, 0xff, 0xff, 0x00, 0x03, 0x00,
	0x00, 0x0a, 0xc0, 0xa8, 0xaa, 0x00, 0xff, 0xff, 0xff, 0x00, 0x03, 0x00, 0x00, 0x0a, 0x00, 0x03,
	0x02, 0x05, 0x50, 0xd4, 0x10, 0x00, 0xc0, 0xa8, 0xaa, 0x02, 0x80, 0x00, 0x00, 0x01, 0x2a, 0x49,
	0x00, 0x24, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x03, 0x02, 0x05, 0x94, 0x79, 0xab, 0x00, 0xc0, 0xa8, 0xaa, 0x02, 0x80, 0x00,
	0x00, 0x01, 0x34, 0xa5, 0x00, 0x24, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x14, 0xc0, 0xa8,
	0xaa, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x05, 0xc0, 0x82, 0x78, 0x00, 0xc0, 0xa8,
	0xaa, 0x02, 0x80, 0x00, 0x00, 0x01, 0xd3, 0x19, 0x00, 0x24, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00,
	0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x05, 0xc0, 0xa8,
	0x00, 0x00, 0xc0, 0xa8, 0xaa, 0x02, 0x80, 0x00, 0x00, 0x01, 0x37, 0x08, 0x00, 0x24, 0xff, 0xff,
	0xff, 0x00, 0x80, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
	0x02, 0x05, 0xc0, 0xa8, 0x01, 0x00, 0xc0, 0xa8, 0xaa, 0x02, 0x80, 0x00, 0x00, 0x01, 0x2c, 0x12,
	0x00, 0x24, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x03, 0x02, 0x05, 0xc0, 0xa8, 0xac, 0x00, 0xc0, 0xa8, 0xaa, 0x02, 0x80, 0x00,
	0x00, 0x01, 0x33, 0x41, 0x00, 0x24, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x14, 0xc0, 0xa8,
	0xaa, 0x0a, 0x00, 0x00, 0x00, 0x00,
}

func TestPacketOSPF2LSUpdate(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF2LSUpdate, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeOSPF}, t)
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv2); ok {
		want := &OSPFv2{
			OSPF: OSPF{
				Version:      2,
				Type:         OSPFLinkStateUpdate,
				PacketLength: 292,
				RouterID:     0xc0a8aa03,
				AreaID:       1,
				Checksum:     0x366b,
				Content: LSUpdate{
					NumOfLSAs: 7,
					LSAs: []LSA{
						LSA{
							LSAheader: LSAheader{
								LSAge:       0x2,
								LSType:      0x1,
								LinkStateID: 0xc0a8aa03,
								AdvRouter:   0xc0a8aa03,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0x3a9c,
								Length:      0x30,
								LSOptions:   0x2,
							},
							Content: RouterLSAV2{
								Flags: 0x2,
								Links: 0x2,
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       0x3,
								LSType:      0x5,
								LinkStateID: 0x50d41000,
								AdvRouter:   0xc0a8aa02,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0x2a49,
								Length:      0x24,
								LSOptions:   0x2,
							},
							Content: ASExternalLSAV2{
								NetworkMask:       0xffffffff,
								ExternalBit:       0x80,
								Metric:            0x14,
								ForwardingAddress: 0x0,
								ExternalRouteTag:  0x0,
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       0x3,
								LSType:      0x5,
								LinkStateID: 0x9479ab00,
								AdvRouter:   0xc0a8aa02,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0x34a5,
								Length:      0x24,
								LSOptions:   0x2,
							},
							Content: ASExternalLSAV2{
								NetworkMask:       0xffffff00,
								ExternalBit:       0x80,
								Metric:            0x14,
								ForwardingAddress: 0xc0a8aa01,
								ExternalRouteTag:  0x0,
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       0x3,
								LSType:      0x5,
								LinkStateID: 0xc0827800,
								AdvRouter:   0xc0a8aa02,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0xd319,
								Length:      0x24,
								LSOptions:   0x2,
							},
							Content: ASExternalLSAV2{
								NetworkMask:       0xffffff00,
								ExternalBit:       0x80,
								Metric:            0x14,
								ForwardingAddress: 0x0,
								ExternalRouteTag:  0x0,
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       0x3,
								LSType:      0x5,
								LinkStateID: 0xc0a80000,
								AdvRouter:   0xc0a8aa02,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0x3708,
								Length:      0x24,
								LSOptions:   0x2,
							},
							Content: ASExternalLSAV2{
								NetworkMask:       0xffffff00,
								ExternalBit:       0x80,
								Metric:            0x14,
								ForwardingAddress: 0x0,
								ExternalRouteTag:  0x0,
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       0x3,
								LSType:      0x5,
								LinkStateID: 0xc0a80100,
								AdvRouter:   0xc0a8aa02,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0x2c12,
								Length:      0x24,
								LSOptions:   0x2,
							},
							Content: ASExternalLSAV2{
								NetworkMask:       0xffffff00,
								ExternalBit:       0x80,
								Metric:            0x14,
								ForwardingAddress: 0x0,
								ExternalRouteTag:  0x0,
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       0x3,
								LSType:      0x5,
								LinkStateID: 0xc0a8ac00,
								AdvRouter:   0xc0a8aa02,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0x3341,
								Length:      0x24,
								LSOptions:   0x2,
							},
							Content: ASExternalLSAV2{
								NetworkMask:       0xffffff00,
								ExternalBit:       0x80,
								Metric:            0x14,
								ForwardingAddress: 0xc0a8aa0a,
								ExternalRouteTag:  0x0,
							},
						},
					},
				},
			},
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket8(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF2LSUpdate, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF3LSUpdate is the packet:
//   14:43:51.681554 IP6 fe80::1 > fe80::2: OSPFv3, LS-Update, length 288
//   	0x0000:  c201 1ffa 0001 c200 1ffa 0001 86dd 6e00  ..............n.
//   	0x0010:  0000 0120 5901 fe80 0000 0000 0000 0000  ....Y...........
//   	0x0020:  0000 0000 0001 fe80 0000 0000 0000 0000  ................
//   	0x0030:  0000 0000 0002 0304 0120 0101 0101 0000  ................
//   	0x0040:  0001 e556 0000 0000 0007 0028 2001 0000  ...V.......(....
//   	0x0050:  0000 0101 0101 8000 0002 d13a 0018 0100  ...........:....
//   	0x0060:  0033 0029 2003 0000 0003 0101 0101 8000  .3.)............
//   	0x0070:  0001 6259 0024 0000 004a 4000 0000 2001  ..bY.$...J@.....
//   	0x0080:  0db8 0000 0003 0029 2003 0000 0002 0101  .......)........
//   	0x0090:  0101 8000 0001 baf6 0024 0000 0054 4000  .........$...T@.
//   	0x00a0:  0000 2001 0db8 0000 0004 0029 2003 0000  ...........)....
//   	0x00b0:  0001 0101 0101 8000 0001 eba0 0024 0000  .............$..
//   	0x00c0:  004a 4000 0000 2001 0db8 0000 0034 0029  .J@..........4.)
//   	0x00d0:  2003 0000 0000 0101 0101 8000 0001 0ebd  ................
//   	0x00e0:  0024 0000 0040 4000 0000 2001 0db8 0000  .$...@@.........
//   	0x00f0:  0000 0023 0008 0000 0005 0101 0101 8000  ...#............
//   	0x0100:  0002 3d08 0038 0100 0033 fe80 0000 0000  ..=..8...3......
//   	0x0110:  0000 0000 0000 0000 0001 0000 0001 4000  ..............@.
//   	0x0120:  0000 2001 0db8 0000 0012 0023 2009 0000  ...........#....
//   	0x0130:  0000 0101 0101 8000 0001 e8d2 002c 0001  .............,..
//   	0x0140:  2001 0000 0000 0101 0101 4000 000a 2001  ..........@.....
//   	0x0150:  0db8 0000 0012                           ......
var testPacketOSPF3LSUpdate = []byte{
	0xc2, 0x01, 0x1f, 0xfa, 0x00, 0x01, 0xc2, 0x00, 0x1f, 0xfa, 0x00, 0x01, 0x86, 0xdd, 0x6e, 0x00,
	0x00, 0x00, 0x01, 0x20, 0x59, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x04, 0x01, 0x20, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
	0x00, 0x01, 0xe5, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x28, 0x20, 0x01, 0x00, 0x00,
	0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x80, 0x00, 0x00, 0x02, 0xd1, 0x3a, 0x00, 0x18, 0x01, 0x00,
	0x00, 0x33, 0x00, 0x29, 0x20, 0x03, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x80, 0x00,
	0x00, 0x01, 0x62, 0x59, 0x00, 0x24, 0x00, 0x00, 0x00, 0x4a, 0x40, 0x00, 0x00, 0x00, 0x20, 0x01,
	0x0d, 0xb8, 0x00, 0x00, 0x00, 0x03, 0x00, 0x29, 0x20, 0x03, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01,
	0x01, 0x01, 0x80, 0x00, 0x00, 0x01, 0xba, 0xf6, 0x00, 0x24, 0x00, 0x00, 0x00, 0x54, 0x40, 0x00,
	0x00, 0x00, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x04, 0x00, 0x29, 0x20, 0x03, 0x00, 0x00,
	0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x80, 0x00, 0x00, 0x01, 0xeb, 0xa0, 0x00, 0x24, 0x00, 0x00,
	0x00, 0x4a, 0x40, 0x00, 0x00, 0x00, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x34, 0x00, 0x29,
	0x20, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x80, 0x00, 0x00, 0x01, 0x0e, 0xbd,
	0x00, 0x24, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x23, 0x00, 0x08, 0x00, 0x00, 0x00, 0x05, 0x01, 0x01, 0x01, 0x01, 0x80, 0x00,
	0x00, 0x02, 0x3d, 0x08, 0x00, 0x38, 0x01, 0x00, 0x00, 0x33, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00,
	0x00, 0x00, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x12, 0x00, 0x23, 0x20, 0x09, 0x00, 0x00,
	0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x80, 0x00, 0x00, 0x01, 0xe8, 0xd2, 0x00, 0x2c, 0x00, 0x01,
	0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x40, 0x00, 0x00, 0x0a, 0x20, 0x01,
	0x0d, 0xb8, 0x00, 0x00, 0x00, 0x12,
}

func TestPacketOSPF3LSUpdate(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF3LSUpdate, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeOSPF}, t)
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv3); ok {
		want := &OSPFv3{
			OSPF: OSPF{
				Version:      3,
				Type:         OSPFLinkStateUpdate,
				PacketLength: 288,
				RouterID:     0x1010101,
				AreaID:       1,
				Checksum:     0xe556,
				Content: LSUpdate{
					NumOfLSAs: 7,
					LSAs: []LSA{
						LSA{
							LSAheader: LSAheader{
								LSAge:       40,
								LSType:      0x2001,
								LinkStateID: 0x00000000,
								AdvRouter:   0x01010101,
								LSSeqNumber: 0x80000002,
								LSChecksum:  0xd13a,
								Length:      24,
							},
							Content: RouterLSA{
								Flags:   0x1,
								Options: 0x33,
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       41,
								LSType:      0x2003,
								LinkStateID: 0x00000003,
								AdvRouter:   0x01010101,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0x6259,
								Length:      36,
							},
							Content: InterAreaPrefixLSA{
								Metric:        74,
								PrefixLength:  64,
								PrefixOptions: 0,
								AddressPrefix: []byte{0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x03},
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       41,
								LSType:      0x2003,
								LinkStateID: 0x00000002,
								AdvRouter:   0x01010101,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0xbaf6,
								Length:      36,
							},
							Content: InterAreaPrefixLSA{
								Metric:        84,
								PrefixLength:  64,
								PrefixOptions: 0,
								AddressPrefix: []byte{0x20, 0x1, 0xd, 0xb8, 0x0, 0x0, 0x0, 0x4},
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       41,
								LSType:      0x2003,
								LinkStateID: 0x00000001,
								AdvRouter:   0x01010101,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0xeba0,
								Length:      36,
							},
							Content: InterAreaPrefixLSA{
								Metric:        74,
								PrefixLength:  64,
								PrefixOptions: 0,
								AddressPrefix: []byte{0x20, 0x1, 0xd, 0xb8, 0x0, 0x0, 0x0, 0x34},
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       41,
								LSType:      0x2003,
								LinkStateID: 0x00000000,
								AdvRouter:   0x01010101,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0xebd,
								Length:      36,
							},
							Content: InterAreaPrefixLSA{
								Metric:        64,
								PrefixLength:  64,
								PrefixOptions: 0,
								AddressPrefix: []byte{0x20, 0x1, 0xd, 0xb8, 0x0, 0x0, 0x0, 0x0},
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       35,
								LSType:      0x8,
								LinkStateID: 0x00000005,
								AdvRouter:   0x01010101,
								LSSeqNumber: 0x80000002,
								LSChecksum:  0x3d08,
								Length:      56,
							},
							Content: LinkLSA{
								RtrPriority:      1,
								Options:          0x33,
								LinkLocalAddress: []byte{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
								NumOfPrefixes:    1,
								Prefixes: []Prefix{
									Prefix{
										PrefixLength:  64,
										PrefixOptions: 0,
										AddressPrefix: []byte{0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x12},
									},
								},
							},
						},
						LSA{
							LSAheader: LSAheader{
								LSAge:       35,
								LSType:      0x2009,
								LinkStateID: 0x00000000,
								AdvRouter:   0x01010101,
								LSSeqNumber: 0x80000001,
								LSChecksum:  0xe8d2,
								Length:      44,
							},
							Content: IntraAreaPrefixLSA{
								NumOfPrefixes: 1,
								RefLSType:     0x2001,
								RefAdvRouter:  0x01010101,
								Prefixes: []Prefix{
									Prefix{
										PrefixLength:  64,
										PrefixOptions: 0,
										Metric:        10,
										AddressPrefix: []byte{0x20, 0x1, 0xd, 0xb8, 0x0, 0x0, 0x0, 0x12},
									},
								},
							},
						},
					},
				},
			},
			Instance: 0,
			Reserved: 0,
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket3(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF3LSUpdate, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF2LSAck is the packet:
// 13:20:20.858322 IP 192.168.170.8 > 192.168.170.2: OSPFv2, LS-Ack, length 44
//	0x0000:  0060 0881 7a70 00e0 18b1 0cad 0800 45c0  .`..zp........E.
//	0x0010:  0040 2bea 0000 0159 b75f c0a8 aa08 c0a8  .@+....Y._......
//	0x0020:  aa02 0205 002c c0a8 aa08 0000 0001 e2f4  .....,..........
//	0x0030:  0000 0000 0000 0000 0000 0e10 0201 c0a8  ................
//	0x0040:  aa02 c0a8 aa02 8000 0001 4a8e 0030       ..........J..0
var testPacketOSPF2LSAck = []byte{
	0x00, 0x60, 0x08, 0x81, 0x7a, 0x70, 0x00, 0xe0, 0x18, 0xb1, 0x0c, 0xad, 0x08, 0x00, 0x45, 0xc0,
	0x00, 0x40, 0x2b, 0xea, 0x00, 0x00, 0x01, 0x59, 0xb7, 0x5f, 0xc0, 0xa8, 0xaa, 0x08, 0xc0, 0xa8,
	0xaa, 0x02, 0x02, 0x05, 0x00, 0x2c, 0xc0, 0xa8, 0xaa, 0x08, 0x00, 0x00, 0x00, 0x01, 0xe2, 0xf4,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x10, 0x02, 0x01, 0xc0, 0xa8,
	0xaa, 0x02, 0xc0, 0xa8, 0xaa, 0x02, 0x80, 0x00, 0x00, 0x01, 0x4a, 0x8e, 0x00, 0x30,
}

func TestPacketOSPF2LSAck(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF2LSAck, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeOSPF}, t)
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv2); ok {
		want := &OSPFv2{
			OSPF: OSPF{
				Version:      2,
				Type:         OSPFLinkStateAcknowledgment,
				PacketLength: 44,
				RouterID:     0xc0a8aa08,
				AreaID:       1,
				Checksum:     0xe2f4,
				Content: []LSAheader{
					LSAheader{
						LSAge:       0xe10,
						LSType:      0x1,
						LinkStateID: 0xc0a8aa02,
						AdvRouter:   0xc0a8aa02,
						LSSeqNumber: 0x80000001,
						LSChecksum:  0x4a8e,
						Length:      0x30,
						LSOptions:   0x2,
					},
				},
			},
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}
func BenchmarkDecodePacketPacket9(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF3LSAck, LinkTypeEthernet, gopacket.NoCopy)
	}
}

// testPacketOSPF3LSAck is the packet:
//   14:43:54.185384 IP6 fe80::1 > ff02::5: OSPFv3, LS-Ack, length 136
//   	0x0000:  3333 0000 0005 c200 1ffa 0001 86dd 6e00  33............n.
//   	0x0010:  0000 0088 5901 fe80 0000 0000 0000 0000  ....Y...........
//   	0x0020:  0000 0000 0001 ff02 0000 0000 0000 0000  ................
//   	0x0030:  0000 0000 0005 0305 0088 0101 0101 0000  ................
//   	0x0040:  0001 9d2c 0000 0005 2001 0000 0000 0202  ...,............
//   	0x0050:  0202 8000 0002 b354 0018 0006 2003 0000  .......T........
//   	0x0060:  0003 0202 0202 8000 0001 4473 0024 0006  ..........Ds.$..
//   	0x0070:  2003 0000 0002 0202 0202 8000 0001 9c11  ................
//   	0x0080:  0024 0006 2003 0000 0001 0202 0202 8000  .$..............
//   	0x0090:  0001 cdba 0024 0006 2003 0000 0000 0202  .....$..........
//   	0x00a0:  0202 8000 0001 efd7 0024 0005 0008 0000  .........$......
//   	0x00b0:  0005 0202 0202 8000 0001 5433 002c       ..........T3.,
var testPacketOSPF3LSAck = []byte{
	0x33, 0x33, 0x00, 0x00, 0x00, 0x05, 0xc2, 0x00, 0x1f, 0xfa, 0x00, 0x01, 0x86, 0xdd, 0x6e, 0x00,
	0x00, 0x00, 0x00, 0x88, 0x59, 0x01, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x05, 0x00, 0x88, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
	0x00, 0x01, 0x9d, 0x2c, 0x00, 0x00, 0x00, 0x05, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02,
	0x02, 0x02, 0x80, 0x00, 0x00, 0x02, 0xb3, 0x54, 0x00, 0x18, 0x00, 0x06, 0x20, 0x03, 0x00, 0x00,
	0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x01, 0x44, 0x73, 0x00, 0x24, 0x00, 0x06,
	0x20, 0x03, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x01, 0x9c, 0x11,
	0x00, 0x24, 0x00, 0x06, 0x20, 0x03, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x80, 0x00,
	0x00, 0x01, 0xcd, 0xba, 0x00, 0x24, 0x00, 0x06, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02,
	0x02, 0x02, 0x80, 0x00, 0x00, 0x01, 0xef, 0xd7, 0x00, 0x24, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00,
	0x00, 0x05, 0x02, 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x01, 0x54, 0x33, 0x00, 0x2c,
}

func TestPacketOSPF3LSAck(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPF3LSAck, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() != nil {
		t.Error("Failed to decode packet:", p.ErrorLayer().Error())
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeOSPF}, t)
	if got, ok := p.Layer(LayerTypeOSPF).(*OSPFv3); ok {
		want := &OSPFv3{
			OSPF: OSPF{
				Version:      3,
				Type:         OSPFLinkStateAcknowledgment,
				PacketLength: 136,
				RouterID:     0x1010101,
				AreaID:       1,
				Checksum:     0x9d2c,
				Content: []LSAheader{
					LSAheader{
						LSAge:       5,
						LSType:      0x2001,
						LinkStateID: 0x00000000,
						AdvRouter:   0x02020202,
						LSSeqNumber: 0x80000002,
						LSChecksum:  0xb354,
						Length:      24,
					},
					LSAheader{
						LSAge:       6,
						LSType:      0x2003,
						LinkStateID: 0x00000003,
						AdvRouter:   0x02020202,
						LSSeqNumber: 0x80000001,
						LSChecksum:  0x4473,
						Length:      36,
					},
					LSAheader{
						LSAge:       6,
						LSType:      0x2003,
						LinkStateID: 0x00000002,
						AdvRouter:   0x02020202,
						LSSeqNumber: 0x80000001,
						LSChecksum:  0x9c11,
						Length:      36,
					},
					LSAheader{
						LSAge:       6,
						LSType:      0x2003,
						LinkStateID: 0x00000001,
						AdvRouter:   0x02020202,
						LSSeqNumber: 0x80000001,
						LSChecksum:  0xcdba,
						Length:      36,
					},
					LSAheader{
						LSAge:       6,
						LSType:      0x2003,
						LinkStateID: 0x00000000,
						AdvRouter:   0x02020202,
						LSSeqNumber: 0x80000001,
						LSChecksum:  0xefd7,
						Length:      36,
					},
					LSAheader{
						LSAge:       5,
						LSType:      0x0008,
						LinkStateID: 0x00000005,
						AdvRouter:   0x02020202,
						LSSeqNumber: 0x80000001,
						LSChecksum:  0x5433,
						Length:      44,
					},
				},
			},
			Instance: 0,
			Reserved: 0,
		}
		if !reflect.DeepEqual(got, want) {
			t.Errorf("OSPF packet processing failed:\ngot  :\n%#v\n\nwant :\n%#v\n\n", got, want)
		}
	} else {
		t.Error("No OSPF layer type found in packet")
	}
}

var testPacketOSPFInvalidLSA = []byte{
	0x5c, 0xfa, 0x00, 0x00, 0xfa, 0x6c, 0xbd, 0xe4, 0x19, 0x72, 0x1d, 0x1f,
	0x08, 0x00, 0x45, 0x00, 0x00, 0xad, 0x00, 0x00, 0x40, 0x00, 0x40, 0x59,
	0x6e, 0xef, 0x6b, 0x96, 0x61, 0x11, 0xb4, 0x96, 0xc0, 0xa8, 0x02, 0x04,
	0x00, 0xa2, 0x80, 0x00, 0x01, 0x1f, 0x08, 0x00, 0x45, 0x00, 0x6f, 0x76,
	0x65, 0x72, 0x66, 0x6c, 0x7f, 0xff, 0x12, 0x12, 0x00, 0x5a, 0xf6, 0x73,
	0xa2, 0xba, 0x81, 0x90, 0x00, 0x01, 0x40, 0x6f, 0x77, 0x20, 0x6f, 0x6e,
	0x20, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x00, 0x00, 0x00, 0x01,
	0x96, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x00, 0x6e, 0x00, 0x6f,
	0x77,
}

func TestPacketOSPFInvalidLSA(t *testing.T) {
	p := gopacket.NewPacket(testPacketOSPFInvalidLSA, LinkTypeEthernet, gopacket.Default)
	if p.ErrorLayer() == nil {
		t.Error("Bad packet decoded successfully")
	}
	checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, gopacket.LayerTypeDecodeFailure}, t)
}

func BenchmarkDecodePacketPacket4(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gopacket.NewPacket(testPacketOSPF3LSAck, LinkTypeEthernet, gopacket.NoCopy)
	}
}