added support for string type
[govpp.git] / vendor / github.com / google / gopacket / layers / igmp_test.go
1 // Copyright 2016, Google, Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree.
6
7 package layers
8
9 import (
10         "testing"
11
12         "github.com/google/gopacket"
13 )
14
15 // igmpv1MembershipReportPacket is the packet:
16 //   02:45:36.033916 IP 10.60.0.132 > 224.0.1.60: igmp v1 report 224.0.1.60
17 //      0x0000:  0100 5e00 013c 0030 c1bf 5755 0800 4500  ..^..<.0..WU..E.
18 //      0x0010:  001c 6a7f 0000 0102 6365 0a3c 0084 e000  ..j.....ce.<....
19 //      0x0020:  013c 1200 0cc3 e000 013c 0000 0000 0000  .<.......<......
20 //      0x0030:  ffff ffff ffff 0452 0000 0000            .......R....
21 var igmpv1MembershipReportPacket = []byte{
22         0x01, 0x00, 0x5e, 0x00, 0x01, 0x3c, 0x00, 0x30, 0xc1, 0xbf, 0x57, 0x55, 0x08, 0x00, 0x45, 0x00,
23         0x00, 0x1c, 0x6a, 0x7f, 0x00, 0x00, 0x01, 0x02, 0x63, 0x65, 0x0a, 0x3c, 0x00, 0x84, 0xe0, 0x00,
24         0x01, 0x3c, 0x12, 0x00, 0x0c, 0xc3, 0xe0, 0x00, 0x01, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25         0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04, 0x52, 0x00, 0x00, 0x00, 0x00,
26 }
27
28 func TestIGMPv1MembershipReportPacket(t *testing.T) {
29         p := gopacket.NewPacket(igmpv1MembershipReportPacket, LinkTypeEthernet, gopacket.Default)
30         if p.ErrorLayer() != nil {
31                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
32         }
33         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIGMP}, t)
34
35         igmp := p.Layer(LayerTypeIGMP).(*IGMPv1or2)
36         if igmp.Type != IGMPMembershipReportV1 {
37                 t.Fatal("Invalid IGMP type")
38         }
39 }
40
41 func BenchmarkDecodeigmpv1MembershipReportPacket(b *testing.B) {
42         for i := 0; i < b.N; i++ {
43                 gopacket.NewPacket(igmpv1MembershipReportPacket, LinkTypeEthernet, gopacket.NoCopy)
44         }
45 }
46
47 // igmpv2MembershipQueryPacket is the packet:
48 //   02:45:28.071636 IP 10.60.0.189 > 224.0.0.1: igmp query v2
49 //      0x0000:  0100 5e00 0001 0001 636f c800 0800 45c0  ..^.....co....E.
50 //      0x0010:  001c 0153 0000 0102 ccd3 0a3c 00bd e000  ...S.......<....
51 //      0x0020:  0001 1164 ee9b 0000 0000 0000 0000 0000  ...d............
52 //      0x0030:  0000 0000 0000 0000 0000 0000            ............
53 var igmpv2MembershipQueryPacket = []byte{
54         0x01, 0x00, 0x5e, 0x00, 0x00, 0x01, 0x00, 0x01, 0x63, 0x6f, 0xc8, 0x00, 0x08, 0x00, 0x45, 0xc0,
55         0x00, 0x1c, 0x01, 0x53, 0x00, 0x00, 0x01, 0x02, 0xcc, 0xd3, 0x0a, 0x3c, 0x00, 0xbd, 0xe0, 0x00,
56         0x00, 0x01, 0x11, 0x64, 0xee, 0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 }
59
60 func TestIGMPv2MembershipQuery(t *testing.T) {
61         p := gopacket.NewPacket(igmpv2MembershipQueryPacket, LinkTypeEthernet, gopacket.Default)
62         if p.ErrorLayer() != nil {
63                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
64         }
65         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIGMP}, t)
66
67         igmp := p.Layer(LayerTypeIGMP).(*IGMPv1or2)
68         if igmp.Type != IGMPMembershipQuery {
69                 t.Fatal("Invalid IGMP type")
70         }
71 }
72 func BenchmarkDecodeigmpv2MembershipQueryPacket(b *testing.B) {
73         for i := 0; i < b.N; i++ {
74                 gopacket.NewPacket(igmpv2MembershipQueryPacket, LinkTypeEthernet, gopacket.NoCopy)
75         }
76 }
77
78 // igmpv2MembershipReportPacket is the packet:
79 //   02:47:32.417288 IP 10.60.5.103 > 239.255.255.253: igmp v2 report 239.255.255.253
80 //      0x0000:  0100 5e7f fffd 0015 58dc d9f6 0800 4600  ..^.....X.....F.
81 //      0x0010:  0020 79f0 0000 0102 ab47 0a3c 0567 efff  ..y......G.<.g..
82 //      0x0020:  fffd 9404 0000 1600 fa01 efff fffd 0000  ................
83 //      0x0030:  0000 0000 0000 0000 0000 0000            ............
84 var igmpv2MembershipReportPacket = []byte{
85         0x01, 0x00, 0x5e, 0x7f, 0xff, 0xfd, 0x00, 0x15, 0x58, 0xdc, 0xd9, 0xf6, 0x08, 0x00, 0x46, 0x00,
86         0x00, 0x20, 0x79, 0xf0, 0x00, 0x00, 0x01, 0x02, 0xab, 0x47, 0x0a, 0x3c, 0x05, 0x67, 0xef, 0xff,
87         0xff, 0xfd, 0x94, 0x04, 0x00, 0x00, 0x16, 0x00, 0xfa, 0x01, 0xef, 0xff, 0xff, 0xfd, 0x00, 0x00,
88         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89 }
90
91 func TestIGMPv2MembershipReport(t *testing.T) {
92         p := gopacket.NewPacket(igmpv2MembershipReportPacket, LinkTypeEthernet, gopacket.Default)
93         if p.ErrorLayer() != nil {
94                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
95         }
96         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIGMP}, t)
97
98         igmp := p.Layer(LayerTypeIGMP).(*IGMPv1or2)
99         if igmp.Type != IGMPMembershipReportV2 {
100                 t.Fatal("Invalid IGMP type")
101         }
102 }
103 func BenchmarkDecodeigmpv2MembershipReportPacket(b *testing.B) {
104         for i := 0; i < b.N; i++ {
105                 gopacket.NewPacket(igmpv2MembershipReportPacket, LinkTypeEthernet, gopacket.NoCopy)
106         }
107 }
108
109 // igmp3v3MembershipQueryPacket is the packet:
110 //   10:07:30.488511 IP 192.168.1.254 > 224.0.0.1: igmp query v3 [max resp time 2.4s]
111 //      0x0000:  0100 5e00 0001 0026 446c 1eda 0800 46c0  ..^....&Dl....F.
112 //      0x0010:  0024 17f1 4000 0102 297b c0a8 01fe e000  .$..@...){......
113 //      0x0020:  0001 9404 0000 1118 ecd3 0000 0000 0214  ................
114 //      0x0030:  0000 0000 0000 0000 0000 0000            ............
115 var igmp3v3MembershipQueryPacket = []byte{
116         0x01, 0x00, 0x5e, 0x00, 0x00, 0x01, 0x00, 0x26, 0x44, 0x6c, 0x1e, 0xda, 0x08, 0x00, 0x46, 0xc0,
117         0x00, 0x24, 0x17, 0xf1, 0x40, 0x00, 0x01, 0x02, 0x29, 0x7b, 0xc0, 0xa8, 0x01, 0xfe, 0xe0, 0x00,
118         0x00, 0x01, 0x94, 0x04, 0x00, 0x00, 0x11, 0x18, 0xec, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x02, 0x14,
119         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120 }
121
122 func TestIGMPv3MembershipQuery(t *testing.T) {
123         p := gopacket.NewPacket(igmp3v3MembershipQueryPacket, LinkTypeEthernet, gopacket.Default)
124         if p.ErrorLayer() != nil {
125                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
126         }
127         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIGMP}, t)
128
129         igmp := p.Layer(LayerTypeIGMP).(*IGMP)
130         if igmp.Type != IGMPMembershipQuery {
131                 t.Fatal("Invalid IGMP type")
132         }
133 }
134
135 func BenchmarkDecodeigmp3v3MembershipQueryPacket(b *testing.B) {
136         for i := 0; i < b.N; i++ {
137                 gopacket.NewPacket(igmp3v3MembershipQueryPacket, LinkTypeEthernet, gopacket.NoCopy)
138         }
139 }
140
141 // igmpv3MembershipReport2Records is the packet:
142 //   10:07:29.756202 IP 192.168.1.66 > 224.0.0.22: igmp v3 report, 2 group record(s)
143 //      0x0000:  0100 5e00 0016 0025 2e51 c381 0800 4658  ..^....%.Q....FX
144 //      0x0010:  0030 013c 0000 0102 8133 c0a8 0142 e000  .0.<.....3...B..
145 //      0x0020:  0016 9404 0000 2200 f33c 0000 0002 0200  ......"..<......
146 //      0x0030:  0000 efc3 0702 0200 0000 efff fffa       ..............
147 var igmpv3MembershipReport2Records = []byte{
148         0x01, 0x00, 0x5e, 0x00, 0x00, 0x16, 0x00, 0x25, 0x2e, 0x51, 0xc3, 0x81, 0x08, 0x00, 0x46, 0x58,
149         0x00, 0x30, 0x01, 0x3c, 0x00, 0x00, 0x01, 0x02, 0x81, 0x33, 0xc0, 0xa8, 0x01, 0x42, 0xe0, 0x00,
150         0x00, 0x16, 0x94, 0x04, 0x00, 0x00, 0x22, 0x00, 0xf3, 0x3c, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00,
151         0x00, 0x00, 0xef, 0xc3, 0x07, 0x02, 0x02, 0x00, 0x00, 0x00, 0xef, 0xff, 0xff, 0xfa,
152 }
153
154 func TestIGMPv3MembershipReport2Records(t *testing.T) {
155         p := gopacket.NewPacket(igmpv3MembershipReport2Records, LinkTypeEthernet, gopacket.Default)
156         if p.ErrorLayer() != nil {
157                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
158         }
159         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIGMP}, t)
160
161         igmp := p.Layer(LayerTypeIGMP).(*IGMP)
162         if igmp.Type != IGMPMembershipReportV3 {
163                 t.Fatal("Invalid IGMP type")
164         }
165 }
166
167 func BenchmarkDecodeigmpv3MembershipReport2Records(b *testing.B) {
168         for i := 0; i < b.N; i++ {
169                 gopacket.NewPacket(igmpv3MembershipReport2Records, LinkTypeEthernet, gopacket.NoCopy)
170         }
171 }